Sign in to follow this  
Followers 0
Ambient

Invalid directory error when Setting NET TIME

3 posts in this topic

#1 ·  Posted (edited)

Hi I am getting an invalid directory error when trying to run the code below even though the command line runs fine.

Would appericiate the help , Thanks in advance.

$padchar="\\"

$sServerString = "%s /c net time %s%s /SET /Y"

$sNetTimeCmd=StringFormat($sServerString, @ComSpec,$padchar,$ServerName)

;$sServerString = "net time \\"& $ServerName &" /SET /Y"

MsgBox(4096, "Result", $sNetTimeCmd)

$timeresult =Run($sNetTimeCmd,@SW_HIDE, 2+4)

;$timeresult =

$TimeOutVar = ""; buffer for StdOut output

$TimeErrVar = ""; buffer for ErrOut output

MsgBox(4096, "Result", $stimeresult & " " & $Timeoutvar & " " & $TimeErrVar)

While 1

$TimeOutVar &= StdoutRead($imeresult)

$TimeErrVar &= StdErrRead($timeresult)

$Timevar = "StdOut:" & @CRLF & $TimeOutVar & @CRLF & "ErrOut:" & @CRLF & $TimeErrVar

_FileWriteLog($logfilepath, "Result of net Time for " & $Servername & " :" & $Timevar)

If @error Then ExitLoop

_FileWriteLog($logfilepath, "Result of net Time for " & $Servername & " :" & $TimeErrvar)

Sleep(100)

WEnd

ConsoleWrite("Debug: " & $timeresult & @LF)

Edited by Ambient

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You've missed the working directory parameter in the Run function, it's trying to use @SW_HIDE as the working dir.

Also, the @error test that you're using to exit the While loop is in a bad place: you're testing the @error state returned by _FileWriteLog, which is not what you want. To get the result you're after you'd have to save the @error results of both StdoutRead and StderrRead, then test both together to see if you're ready to exit the loop.

Finally, you might be happier with the _FileWriteLog calls outside the While loop, else you might have multiple/empty writes to the log before you've gotten all your output.

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

You've missed the working directory parameter in the Run function, it's trying to use @SW_HIDE as the working dir.

Also, the @error test that you're using to exit the While loop is in a bad place: you're testing the @error state returned by _FileWriteLog, which is not what you want. To get the result you're after you'd have to save the @error results of both StdoutRead and StderrRead, then test both together to see if you're ready to exit the loop.

Finally, you might be happier with the _FileWriteLog calls outside the While loop, else you might have multiple/empty writes to the log before you've gotten all your output.

Thanks a million works a treat now, much appericiated!

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