Sign in to follow this  
Followers 0
ZipleR

[Solved] Run simple command line apps on 64Bit server

4 posts in this topic

#1 ·  Posted (edited)

Hey everyone... I am trying to build a script to manage a Citrix farm. I do not want the script to sit on each server, so I have it stored on a network share. The script has several functions built in that call command line tools such as msg.exe, shutdown.exe, schtasks.exe, etc...

I am having a problem where the run command is not firing off the tools I am calling - or the execution is being blocked somehow. Below is one of the functions that I have created which is not working.

I have tried the @ComSpec & " /c, and even captured the output (which is blank as expected).

I did take the Command string (after Run) and place it into a input box so I could select and copy exactly what is being "Run", and the command that was in the input box works as expected when pasted into a command window.

The $LocalList is being passed from a different function that selects the appropriate servers - so in the example below I just created a generic array of servers.

Please let me know if you have any ideas.

The script is running on Server 2003R2 x64.

Dim $ServerList[5]=[4,"Server1","Server2","server3","Server4"]

$Result = ForceReboot($serverList);Calls Function passing Array of Servers.

Exit

Func ForceReboot($LocalList)
    If $LocalList[0] > 0 then ;If the list of servers is blank - skips this function.
        For $y = 1 to $LocalList[0] ;Loops through list of servers
            Run ('Shutdown /r /f /t 600 /d p:4:1 /c "Weekly Scheduled Reboot" /m \\' & $LocalList[$y],@SystemDir )
        Next ;Goes to the next server in the list
        Return(1) ;Returns 1 for Success
    Else
        Return(0) ;Returns 0 for Failure
    EndIf

EndFunc
Edited by ZipleR

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you add a @SW_MAXIMIZE parameter to the run command can you verify that the shutdown command is being ran at all? Is there an anti-virus/network security software affecting this?

Edited by evilertoaster

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok... I figured this out by using ProcMon. The 64bit WOW redirection was messing with the search path for shell commands. (as well as registry changes)

I was having the same problem when trying to copy files to the System32 folder using a batch file on other 64 bit servers a while back.

To fix it in Autoit - do the following to disable Wow64DisableWow64FsRedirection

Dim $ServerList[5]=[4,"Server1","Server2","server3","Server4"]

$Result = ForceReboot($serverList);Calls Function passing Array of Servers.

Exit

Func ForceReboot($LocalList)
    If $LocalList[0] > 0 then ;If the list of servers is blank - skips this function.
        For $y = 1 to $LocalList[0] ;Loops through list of servers
            DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1);Turns off 64 bit redirection   
            Run ('Shutdown /r /f /t 600 /d p:4:1 /c "Weekly Scheduled Reboot" /m \\' & $LocalList[$y],@SystemDir )
            DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0);Turns 64 bit redirection back on
        Next ;Goes to the next server in the list
        Return(1) ;Returns 1 for Success
    Else
        Return(0) ;Returns 0 for Failure
    EndIf

EndFunc
Edited by ZipleR

Share this post


Link to post
Share on other sites

If you add a @SW_MAXIMIZE parameter to the run command can you verify that the shutdown command is being ran at all? Is there an anti-virus/network security software affecting this?

Yeah. I thought it was maybe some type of security built into windows. We use McAfee, and there was nothing being logged in the logs relating to it...

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  
Followers 0