Problem deploying cmd script with snapin
-
Hi,
I create a snapin to set a shortcut for some computers in “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp”, which requires administrator privilege.
I found a way to add some line to execute this cmd script with administrator privileges, and it works like a charm when I launch it form my computer.
But when I deploy this script with fog snapin in another computer, snapin seems to deploy (o error in fog.log) but shortcut don’t appear…
Any idea ?
Here is the script (to clone display between monitor and videoprojector on teacher computers in classroom)REM --add the following to the top of your bat file-- @echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" set params = %*:"="" echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin pushd "%CD%" CD /D "%~dp0" :-------------------------------------- @echo off Cls set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs" echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT% echo sLinkFile = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Clone.lnk" >> %SCRIPT% echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT% echo oLink.TargetPath = "%windir%\System32\DisplaySwitch.exe" >> %SCRIPT% echo oLink.Arguments = "/clone" >> %SCRIPT% echo oLink.Save >> %SCRIPT% cscript /nologo %SCRIPT% del %SCRIPT%
And the result in fog.log
------------------------------------------------------------------------------ ---------------------------------SnapinClient--------------------------------- ------------------------------------------------------------------------------ 14/09/2016 11:18 Client-Info Client Version: 0.11.5 14/09/2016 11:18 Client-Info Client OS: Windows 14/09/2016 11:18 Client-Info Server Version: 1.3.0-RC-10 14/09/2016 11:18 Middleware::Response Success 14/09/2016 11:18 SnapinClient Snapin Found: 14/09/2016 11:18 SnapinClient ID: 1381 14/09/2016 11:18 SnapinClient Name: Clone 14/09/2016 11:18 SnapinClient Created: 2016-09-14 11:17:34 14/09/2016 11:18 SnapinClient Action: 14/09/2016 11:18 SnapinClient Pack: False 14/09/2016 11:18 SnapinClient Hide: False 14/09/2016 11:18 SnapinClient Server: 14/09/2016 11:18 SnapinClient TimeOut: 0 14/09/2016 11:18 SnapinClient RunWith: c:\windows\system32\cmd.exe 14/09/2016 11:18 SnapinClient RunWithArgs: /c 14/09/2016 11:18 SnapinClient Args: 14/09/2016 11:18 SnapinClient File: Clone2.cmd 14/09/2016 11:18 Middleware::Communication Download: http://192.168.10.60/fog/service/snapins.file.php?mac=E8:40:F2:3B:C7:AA&taskid=1381 14/09/2016 11:18 SnapinClient C:\Program Files (x86)\FOG\tmp\Clone2.cmd 14/09/2016 11:18 Bus { "self": true, "channel": "Notification", "data": "{\r\n \"title\": \"Installing Clone\",\r\n \"message\": \"Please do not shutdown until this is completed\"\r\n}" } 14/09/2016 11:18 Bus Emmiting message on channel: Notification 14/09/2016 11:18 SnapinClient Starting snapin... 14/09/2016 11:18 SnapinClient Snapin finished 14/09/2016 11:18 SnapinClient Return Code: 0 14/09/2016 11:18 Bus { "self": true, "channel": "Notification", "data": "{\r\n \"title\": \"Clone Installed\",\r\n \"message\": \"Installation has finished and is now ready for use\"\r\n}" } 14/09/2016 11:18 Bus Emmiting message on channel: Notification 14/09/2016 11:18 Middleware::Communication URL: http://192.168.10.60/fog/service/snapins.checkin.php?taskid=1381&exitcode=0&mac=E8:40:F2:3B:C7:AA&newService&json ------------------------------------------------------------------------------
-
Some other test :
- double-clicking on script “Clone2.cmd” in my computer create shortcut
- launching command “c:\windows\system32\cmd.exe /C Clone2.cmd” on my computer create shortcut
- BUT deploying fog snapin with command “c:\windows\system32\cmd.exe /C Clone2.cmd” failed to create shortcut…
-
Fairly certain the problem is that Snapins run under the System account, which cannot interact with the desktop, and thus you can’t “elevate” to administrator.
-
@Quazz Oh, so it will be problematic…
I absolutely need to force clone display on these computers, if not after deploying image principal screen is videoprojector so people can’t log on computer… -
@Matthieu-Jacquart Windows Key + P is the shortcut to switch display mode, works on login screen too.
Not sure about how to force it using snapins though.
-
@Matthieu-Jacquart a couple things. SYSTEM sometimes won’t have the
TEMP
environment all variable set (yes, I know that’s weird). I also see you are using a batch script to offload to a vbs. Try removing that additional complexity by sticking to one language. Either write it in just batch or just vbs.Also, if its a snap in you can remove all of your UAC checks to further limit potentional points of failure.
But as said before, it may just simply be that SYSTEM can’t clone displays. In which case you could use a snap in to write to a login script that gets run everytime a user logs in.
-
Thanks for help, finally I created a snapin which add registry key to duplicate display when someone log in, and if needed after deploying image I use Win + P key.
-
Server :
FOG Version: 1.4.2 SVN 6072
OS: Debian 8Client :
Service Version: SmartInstaller v0.11.12
OS: Win7x64 PRODescription :
Hi,
I’m really sorry for the “UP” but i try to have more verbose logs for the Snapins …
In my case, for SnapinPack, into the fog.log, i have “just” this :------------------------------------------------------------------------------ ---------------------------------SnapinClient--------------------------------- ------------------------------------------------------------------------------ 12/01/2018 16:07 Client-Info Client Version: 0.11.12 12/01/2018 16:07 Client-Info Client OS: Windows 12/01/2018 16:07 Client-Info Server Version: 1.4.2 12/01/2018 16:07 Middleware::Response Success 12/01/2018 16:07 SnapinClient Running snapin algobox_64 12/01/2018 16:07 Middleware::Communication Download: http://xxx.xxx.xxx.xxx/fog/service/snapins.file.php?mac=xx:xx:xx:xx:xx:xx||00:00:00:00:00:00:00:E0|00:00:00:00:00:00:00:E0&taskid=xxx 12/01/2018 16:07 SnapinClient C:\Program Files (x86)\FOG\tmp\algobox_x64.zip 12/01/2018 16:07 SnapinClient Processing SnapinPack algobox_x64.zip 12/01/2018 16:07 SnapinClient Extracting SnapinPack 12/01/2018 16:07 Bus Emmiting message on channel: Notification 12/01/2018 16:07 SnapinClient Starting snapin 12/01/2018 16:07 SnapinClient Snapin finished 12/01/2018 16:07 SnapinClient Return Code: 0 12/01/2018 16:07 Bus Emmiting message on channel: Notification 12/01/2018 16:07 Middleware::Communication URL: ............... ------------------------------------------------------------------------------```
In your case, it’s seem to be more verbose …
------------------------------------------------------------------------------ ---------------------------------SnapinClient--------------------------------- ------------------------------------------------------------------------------ 14/09/2016 11:18 Client-Info Client Version: 0.11.5 14/09/2016 11:18 Client-Info Client OS: Windows 14/09/2016 11:18 Client-Info Server Version: 1.3.0-RC-10 14/09/2016 11:18 Middleware::Response Success 14/09/2016 11:18 SnapinClient Snapin Found: 14/09/2016 11:18 SnapinClient ID: 1381 14/09/2016 11:18 SnapinClient Name: Clone 14/09/2016 11:18 SnapinClient Created: 2016-09-14 11:17:34 14/09/2016 11:18 SnapinClient Action: 14/09/2016 11:18 SnapinClient Pack: False 14/09/2016 11:18 SnapinClient Hide: False 14/09/2016 11:18 SnapinClient Server: 14/09/2016 11:18 SnapinClient TimeOut: 0 14/09/2016 11:18 SnapinClient RunWith: c:\windows\system32\cmd.exe 14/09/2016 11:18 SnapinClient RunWithArgs: /c 14/09/2016 11:18 SnapinClient Args: 14/09/2016 11:18 SnapinClient File: Clone2.cmd 14/09/2016 11:18 Middleware::Communication Download: http://192.168.10.60/fog/service/snapins.file.php?mac=E8:40:F2:3B:C7:AA&taskid=1381 14/09/2016 11:18 SnapinClient C:\Program Files (x86)\FOG\tmp\Clone2.cmd 14/09/2016 11:18 Bus { "self": true, "channel": "Notification", "data": "{\r\n \"title\": \"Installing Clone\",\r\n \"message\": \"Please do not shutdown until this is completed\"\r\n}" }
It’s a fog version problem or it’s just a specific configuration checked in the Global Configuration GUI ?
Many thanks for your help
-
@Jonathan-Cool AFAIK it’s just the older version that had other/more debug output.
-
@sebastian-roth said in Problem deploying cmd script with snapin:
AFAIK it’s just the older version that had other/more debug output.
Correct. @joe-schmitt made that change over some security concerns.
-
Thanks for reply.
There is a way to have more verbose snapin output with the new version of fog client ? -
@jonathan-cool Yes, you would just code that functionality into your script. Have it dump variables to a text file, dump errors to a text file, etc.
-
Thank you for your reply.
I will try that