Link to home
Start Free TrialLog in
Avatar of Reyesrj
ReyesrjFlag for Guam

asked on

scripting

Hi,
I’m running a windows 7 pc and I would like to run a gpupdate / force script.  I used a text file and typed in gpupdate /force and saved it as GP.bat.  When I double click the on the bat file it just keeps running the gpupdate /force command continuously and rapidly.  How do I get it to run once and exit the command promt?
Avatar of TJCombos
TJCombos
Flag of United States of America image

you can write a C# console program with process and set wait on exit on that process then terminate the program after process is completed.
Avatar of X Layer
You probably did something wrong. I've tried this and runs command once and then exits.
You called the batch file gpupdate.cmd perhaps?  That would loop back and run itself in a loop...
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

Another thing you can do at a command prompt in Windows 7 is type:

where gpupdate

and it should show you all the possible items it would run.  If you do see a BAT or CMD file in the list then as Steve mentioned, you may have a case where the script is calling itself, rather than the EXE.

~bp
Just a wild guess from a sleepy guy! Have you tried to run your batch file as Administrator?
"Right click" on "GP.bat", Run As Administrator.
And in the interest of thoroughness, take a look at the Windows Event logs, in the "System" log and see if there are any messages from GroupPolicy in there.

~bp
Avatar of Reyesrj

ASKER

Dude, you are good!
I did call it gpupdate.bat
So the command can't be the name of the file.
THANK YOU!!!
No problem, gets us all sometimes... calls itself then in an infinite loop :-)
searched all over google for this answer and you were right - it's because I called it gpupdate.bat as well. Can someone help me better understand why calling the first part of the name causes an infinite loop? regardless if it's .bat or .cmd?
If you type or run from within a batch file just the command "gpupdate" then it looks in the current directory for (I think the order is)

gpupdate.com
gpupdate.exe
gpupdate.bat
gpupdate.cmd
gpupdate.vbs
etc. + various others until it finds one, and it not in the current dir then it looks down the path until it gets to c:\windows\system32 and finds gpupdate.exe

So.... call it gpupdate.bat / .cmd and if in that batch file you use gpupdate then it runs itself again as it finds itself before the real gpupdate.exe

You could use "%windir%\system32\gpupdate.exe" within a file called gpupdate.bat to specifically get that exe, or do

@echo off
cd /d "%windir%\system32"
gpupdate.exe /force

But easier... don't call it gpupdate.bat

Steve
Thanks Steve. I completely understand now. Thanks!