Search code examples
vbscript

A bit complex Vbs


I have to create a vscript a bit complex, at least for me.. If anyone could help, I will thank you so much! :D

these are the tasks that the script needs to take care of:

*-run this cmd file located on "C:\Program Files\Paradigm\Paradigm-15\Services\bin\cli\PG_epos_user_list.cmd" -pns_host localhost

that cmd generates a list of users so, from this cmd's output, I need to check if current logged accountname are listed there (check if it matches)*

-If it is not listed, run another cmd -> "C:\Program Files\Paradigm\Paradigm-15\Services\bin\cli\PG_epos_user_create.cmd" -pns_host localhost -epos_user -member_list

but in this case, we have to input logged userid on each "" on that commandline.

then, compare the content on a ini file, stored on a shared disk, with the values on 2 files located on C:\ProgramData\Paradigm\Paradigm-15\Applications\config\env\common\

1_epos_license_location  & 1_epos_license_location.tcl 

Get the license value from section "[License]" value Stratimagic=**licensevalue** and be sure that matches with the license info on both 1_epos_license_location & 1_epos_license_location.tcl.

If it not matches, update both files. Also, check if W disk is mapped, if not, advise with a msgbox

Thanks guys!,I have this so far (working), all the italic part, is working.

dim objshell

    sub runCommand(strCommand)
       Dim oShell
       Set oShell = CreateObject("WScript.Shell")
       oShell.Run strCommand, 0, TRUE
    end sub

Private Function File2Output(tempfile)
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set txtStream = fso.OpenTextFile(tempfile, 1)
        out = ""
        out = txtStream.ReadAll
        txtStream.Close
        fso.DeleteFile tempfile
        File2Output = out
End Function


call runCommand("%COMSPEC% /c ""C:\Program Files\Paradigm\Paradigm-15\Services\bin\cli\PG_epos_user_list.cmd"" -pns_host localhost > c:\log.txt")

Set objNetwork = CreateObject("Wscript.Network")

user = objNetwork

cmdOut = File2Output("c:\log.txt")
'WScript.echo cmdout
'WScript.echo user
'WScript.echo InStr(cmdOut, user)
if InStr(cmdOut, user) > 0 Then
                WScript.echo "Found"
Else
                WScript.echo "Not Found"
End if

Thanks in advance!, Regards


Solution

  • sub runCommand(strCommand)
       Dim oShell
       Set oShell = CreateObject("WScript.Shell")
       objShell.Run strCommand, 0, TRUE
    end sub
    

    To run commands:

    this will call the sub and run your command. The last portion of the command (> c:\temp\log.txt) will actually dump the results of the command into the log.txt file, so right after the execution you can actually open the file and parse the results, thus allowing you to make decisions on how to proceed with the script.

    call runCommand("%COMSPEC% /c C:\Program Files\Paradigm\Paradigm-15\Services\bin\cli\PG_epos_user_list.cmd > c:\temp\log.txt")
    

    Then, to get the current user:

    Set objNetwork = CreateObject("Wscript.Network")
    Wscript.Echo "The current user is " & objNetwork.UserName
    

    ** for further reference on the run method: https://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx

    Hope this helps.