Jump to content
Sign in to follow this  
watsonle

RunWait@ComSpec question

Recommended Posts

watsonle

I have developed a Client/Server script to manage WSUS server patch management and have one last issue to resolve that so far has stumped me.

I use the following command (see below )on the sever side to run Microsoft Patch Verification. I want to pass the user name /u and password /v as a varibles so that I can prompt the user (client) for the credentials and pass it on to the Servers mbsacli command.

Below is the command that I used to scan a target client. I want to get away having to use if statements and hardcoding the usernames and passwords.

If $AdminName = "Administrator" AND $Password = "P@33word!" then

RunWait(@ComSpec & " /c " & '"C:\Program Files\Microsoft Baseline Security Analyzer 2\mbsacli.exe" /u administrator /p P@33word! /wa /ia /n IIS+OS+Password /target ' & _TCP_Server_ClientIP($hSocket) & " > " & $reportPath & $reportName, "", @SW_HIDE)

Any help appreciated!

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, watsonle. Check out InputBox in the help file for your prompts. Something like this (you can mask the password characters with any symbol you choose):

$uID = InputBox("", "Please enter your username")
$pw = InputBox("", "Please enter your password", "", "*")

You can then pass the variables into your command line:

RunWait(@ComSpec & " /c " & '"C:Program FilesMicrosoft Baseline Security Analyzer 2mbsacli.exe" /u' & $uID & ' /p ' & $pw & ' /wa /ia /n IIS+OS+Password /target ' & _TCP_Server_ClientIP($hSocket) & " > " & $reportPath & $reportName, "", @SW_HIDE)
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
watsonle

Thanks for the input! I had tried the modification you suggested (see below )

When I break at the RunWait command and look at the contents of $AdminName and $Password they have the correct data but when I allow the RunWait command to execute it appears that the mbsacli.exe command is not passing the values with the /u and /p switch.

If I replace the /u ' & $AdminName & ' and the /p ' & $Password & ' with the actual /u administrator name and /p password the mbsacli.exe command works as expected.

Seems like it should work. I am still looking.

RunWait(@ComSpec & " /c " & '"C:Program FilesMicrosoft Baseline Security Analyzer 2mbsacli.exe" /u ' & $AdminName & ' /p ' & $Password & '/wa /ia /n IIS+OS+Password /target ' & _TCP_Server_ClientIP($hSocket) & " > " & $reportPath & $reportName, "", @SW_HIDE)

Share this post


Link to post
Share on other sites
JLogan3o13

What happens if you do a RunAs or ShellExecute, rather than using @Comspec?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
watsonle

I think that I found the problem at least it works now. I added a space in the command line between the ' and the /wa script. Seen above there was no space. Not sure if that could have casued the issue but now it does seem fixed and now I can remotely pass the administrator name and password to the server script on the WSUS server and correctly run the mbsacli.exe command against a remote client.

This was the last issue and now lets the user pass the correct credentials without having to code alot of possibilities.

I could not use the RunAs command as I needed to wait for the mbsacli command to complete.

Thanks so much for your suggestion!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • California
      By California
      Hello,
      I wrote a benchmark script to measure variable declarations
      to find out whether you should focus more on static or global variables
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 #ce ---------------------------------------------------------------------------- #Region Pre-Setting Local $iTally1 = 0 Local $iTally2 = 0 Local $iTally3 = 0 Local $iTally4 = 0 Local $iTally5 = 0 Local $iTally6 = 0 Local $iTally7 = 0 Global $GLOBALCONST1 = 1 Global $GLOBALCONST2 = 1 Global $GLOBALCONST3 = 1 Global $GLOBALCONST4 = 1 Global $GLOBALCONST5 = 1 #EndRegion Pre-Setting #Region Test Functions Func s1() Static $i = $GLOBALCONST1 Return $i EndFunc Func g2() Return $GLOBALCONST2 EndFunc Func g3() Static $i7 = "gsdgdfegbgbrwefw" Return $GLOBALCONST3 EndFunc Func g4() Static $i1 = 1 Static $i2 = "asd" Static $i3 = 234 Static $i4 = True Static $i5 = [0] Static $i6 = "hgsdg" Static $i7 = 1 Static $i8 = 1 Static $i9 = 1 Static $i0 = 1 Return $GLOBALCONST4 EndFunc Func g5() Local $i = $GLOBALCONST5 Return $i EndFunc Func g6() Local $i = 1 Return $i EndFunc Func g7() Return 1 EndFunc #EndRegion Test Functions #Region Benchmark Loop For $i = 0 To 15 Local $tDelta = TimerInit() Do $iTally1 += s1() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally2 += g2() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally3 += g3() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally4 += g4() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally5 += g5() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally6 += g6() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally7 += g7() Until TimerDiff($tDelta) >= 1000 Next #EndRegion Benchmark Loop ConsoleWrite(@CRLF&"Static1: "&$iTally1&" pkt"&@CRLF&"Global2: "&$iTally2&" pkt"&@CRLF&"Global3: "&$iTally3&" pkt"&@CRLF&"Global4: "&$iTally4&" pkt"&@CRLF&"Local5: "&$iTally5&" pkt"&@CRLF&"Local6: "&$iTally6&" pkt"&@CRLF&"Hardcode7:"&$iTally7&" pkt"&@CRLF) #cs Result Static1: 10291881 pkt global to static Global2: 13977324 pkt only global Global3: 9886169 pkt global and static Global4: 2933051 pkt global and many statics Local5: 9937314 pkt global to local Local6: 10306484 pkt only local Hardcode7: 14835319 pkt no variable #ce Result:
      100% no variable, hardcore value
      94% only global variable use
      69% only local variable use with hardcore value set
      69% only static variable use with global variable value set
      67% declaration of local variable with global variable value set
      66% only global variable use with one static variable beside
      20% only global variable use with ten static variables beside
      My thesis of the result:
      Be careful with declarations, whether local, global or static Note: in my test the global variable performance was better than the local one, but in practice the global one would lose performance due to multiple operations
       
      What is your best practice sharing data between multiple functions?
    • TheAutomator
      By TheAutomator
      Is this better to check a variable before you assign it to a value that could be the same?
      for example:
      local $EmptyLog = false func WriteLog($text) _guictrledit_appendtext($log, ($EmptyLog ? @CRLF : $empty) & $text) If $EmptyLog Then $EmptyLog = False endfunc or does AutoIt behind the scenes already check this?
      i guess overwriting memory with the same value over and over again is not good if you can prevent this with a check?
    • JNutt
      By JNutt
      I see $hWnd used as a local variable in a lot of script examples.  I know the 'h' is used for handles, but what is the 'Wnd' short for?
      Thanks!
    • Rskm
      By Rskm
      i have seen many pointing out issues related to this, i tried reading through them - still unable to solve mine.. i have a script which reads certain lines based on a search item, this is an iterative process - the ldflst_file gets updated for each iteration and the script finds the line number which has the search item. this works perfectly for few iterations, but stops in some cases abruptly with the error = 
      Subscript used on non-accessible variable $aRead^ ERROR I have verified that the search item is present in the file. what could be the reason for this code to stop in certain cases. thanks for help
      my code below (partial).. full code is in attachment
       
      local $aRead=FileReadToArray($ldflst_file)
      global $ldflst_var1=" JOINT  LOAD       FORCE(X)        FORCE(Y)        FORCE(Z)       MOMENT(X)       MOMENT(Y)       MOMENT(Z)"
       
      for $i= 0 to $ldflst_totlines    ; ldflst_totlines is total number of  lines in the file 'ldflst_file'

          if $aRead[$i]=$ldflst_var1 Then
              $ldflst_LFound=$i
              ExitLoop
              else
              EndIf
      Next
       
       
      nomo_new1.au3
    • kartune
      By kartune
      Hello, i'm trying to rename a variable to another variable name (not the value attached to the variable).  This would save me TONS of coding.
      Here is an example:
       
      <autoit>
      Local $clear1="$SATJ"  ;sets the $clear1 variable to become $SATJ
      GUICtrlSetState($clear1 & "3", $GUI_UNCHECKED)  ;i want this to come out to be $SATJ3, it should look something like - GUICtrlSetState($SATJ3, $GUI_UNCHECKED)
      </autoit>
      Is this possible?  I've been searching all the forums and help files for hours.  My javascript friend referenced me to the solution on JS, which lead me to searching through the "assign" help on autoit, but not much info on it.
      I've already tried
      <autoit>
      Assign($clear1, $SATJ)
      </autoit>
       
      any help is greatly appreciated!!! 
×