Simple batch script help

bealzz

Gawd
Joined
Jun 4, 2003
Messages
545
Im trying to do a gpupdate /force without user intervention but at the end it comes up with a 'OK to logoff?. (Y/N)' and I want to auto answer no.
Is there anyway to do this in a batch script

Code:
@echo off
gpupdate /force
echo N

Something like that, but actually works?

Thanks!
 
here's a vbs that works

'====================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strInputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "input.txt"

Set objInputFile = objFSO.CreateTextFile(strInputFile, True)
objInputFile.WriteLine "n"
objInputFile.WriteLine "n"
objInputFile.Close
Set objInputFile = Nothing

strInputFile = objFSO.GetFile(strInputFile).ShortPath

' FOR TESTING, USE /k and 1, AFTER TESTING, USE /c and 0
strCommand = "cmd /k gpupdate /force < " & strInputFile
objShell.Run strCommand, 1, True

objFSO.DeleteFile strInputFile, True
Set objFSO = Nothing
Set objShell = Nothing

' The line below can be commented out when you have finished testing to keep it silent.
MsgBox "Script finished."
'====================
 
here's a vbs that works

'====================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strInputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "input.txt"

Set objInputFile = objFSO.CreateTextFile(strInputFile, True)
objInputFile.WriteLine "n"
objInputFile.WriteLine "n"
objInputFile.Close
Set objInputFile = Nothing

strInputFile = objFSO.GetFile(strInputFile).ShortPath

' FOR TESTING, USE /k and 1, AFTER TESTING, USE /c and 0
strCommand = "cmd /k gpupdate /force < " & strInputFile
objShell.Run strCommand, 1, True

objFSO.DeleteFile strInputFile, True
Set objFSO = Nothing
Set objShell = Nothing

' The line below can be commented out when you have finished testing to keep it silent.
MsgBox "Script finished."
'====================
I found that on Experts Exchange. It looks like it creates a file called input.txt (I'm sure you could change the path to that file too).
 
OK, ignore that vbs file. Here's a better way,

gpupdate /force /wait:0

It works perfectly. :D
 
Thanks guys, it looks like that last one works,
I found this though and it seems to work too, thought I'd post it just in case anyone else ever wonders.

Code:
echo n | gpupdate /force
 
Thanks guys, it looks like that last one works,
I found this though and it seems to work too, thought I'd post it just in case anyone else ever wonders.

Code:
echo n | gpupdate /force

that only works if it asks one question...in my environment we have scripts that run at log-off and log-on so it asks if you want to reboot then asks if you want to log-off, it freezes cmd.exe on my machine.
 
Back
Top