0

I need help making GPupdate /force fully invisible to the user.

I've seen this in the past. Currently it answers a question to not log the user off the PC automatically but I would like to have the batch close visually but finish the gpupdate in the background.

@echo off
Title Internet Explorer Full Reset

::Close Internet Explorer tasks
taskkill.exe /f /im iexplore.exe

::Wait
timeout /t 4

::Performs reset on all settings for Internet Explorer
reg delete "HKCU\Software\Microsoft\Internet Explorer" /f

::Wait
timeout /t 2

::Clear all temporary internet files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

::Clear all cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

::Clear all form data
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

::Wait
timeout /t 1

:: Set IE to always check for new versions of pages automatically
::reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /V SyncMode5 /t REG_DWORD /d 3 /f

::Wait
timeout /t 1

::Enable favorites bar in Internet Explorer
REG ADD "HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MINIE" /V "LinksBandEnabled" /D "00000001" /F

::Enable menu bar in Internet Explorer
REG ADD "HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MINIE" /V "AlwaysShowMenus" /D "00000001" /F

::Enable command bar in Internet Explorer
REG ADD "HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MINIE" /V "CommandBarEnabled" /D "00000001" /F

::Enable status bar in Internet Explorer
REG ADD "HKCU\SOFTWARE\MICROSOFT\INTERNET EXPLORER\MINIE" /V "ShowStatusBar" /D "00000001" /F

::Relaunch Internet Explorer
start iexplore.exe

::Update Group Policy to bring all Internet Explorer settings back into compliance
echo N | gpupdate /force

::Schedule task to reboot at 11:59PM
::schtasks /create /sc once /tn restart /tr "shutdown -r -f ""restart""" /st 23:59

::Message To User
msg * "Please restart your computer to complete configuration changes when you are next able."
Matthew Horvath
  • 186
  • 1
  • 12
mcavanaugh418
  • 127
  • 1
  • 12
  • 4
    If you close the window you will also close the running script. Your solution is to either minimise the window or to hide the window utilising another programming language/third party utility. – Compo Mar 02 '17 at 15:03
  • isn't there a way to tell a command to run in the background instead of the foreground? – mcavanaugh418 Mar 02 '17 at 15:11
  • Not without using another scripting language like VBscript, or a third party program. – Squashman Mar 02 '17 at 15:30
  • If async ok for you `gpupdate /force /wait:0` If minimized in another window ok for you `start /min gpupdate /force /wait:idntknow` – vitalygolub Mar 02 '17 at 16:15
  • 3
    Possible duplicate of [How can I run a program from a batch file without having the console open after the program start?](http://stackoverflow.com/questions/324539/how-can-i-run-a-program-from-a-batch-file-without-having-the-console-open-after) – phuclv Mar 03 '17 at 02:15
  • 1
    a lot of duplicates: [How to call CMD without opening a window](http://stackoverflow.com/q/4277963/995714), [Launch a program from command line without opening a new window](http://stackoverflow.com/q/12010103/995714), [Run a batch file in a completely hidden way](http://superuser.com/q/62525/2413860)... – phuclv Mar 03 '17 at 02:16

1 Answers1

0

I use a simple VBScript for cases like this. Use the command start "" "directory\update.vbs". The contents of the VBScript (named update.vbs) are as follows:

Const HIDDEN_WINDOW = 12 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set objStartup = objWMIService.Get("Win32_ProcessStartup") 

Set objConfig = objStartup.SpawnInstance_ 
objConfig.ShowWindow = HIDDEN_WINDOW 
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") 
errReturn = objProcess.Create("DIRECTORY\update.bat", null, objConfig, intProcessID)

Please note that you will have to replace DIRECTORY\update.bat with the file directory and name of your batch file. This should run it completely silently (user doesn't see a thing).

Matthew Horvath
  • 186
  • 1
  • 12