Share via


Running a Command Line via a Package

Question

Monday, February 24, 2014 12:52 PM

Hi,

I am trying to deploy the following command line via a package to my servers but for some reason the results are as expected. The command I am trying to run is:

reg add "hklm\software\microsoft\windows nt\currentversion\softwareprotectionplatform" /f /v "KeyManagementServiceName" /t reg_sz /d "dc4hmancmddc1.mydomain.local"

When I look in the log files on the server the command is being executed as:

<![LOG[Command line = "C:\Windows\system32\reg.exe" add "hklm\software\microsoft\windows nt\currentversion\softwareprotectionplatform" /f /v "KeyManagementServiceName" /t reg_sz /d "dc4hmancmddc1.mydomain.local", Working Directory = C:\Windows\system32\LOG]!><time="12:44:32.391+00" date="02-24-2014" component="execmgr" context="" type="1" thread="3976" file="scriptexecution.cpp:346">

Why is this is not working? If I run the command manually on the server, it works and reg key is updated correctly.

PS: I am probably being really stupid here but any help is appreciated.

Thank You

Mayur

All replies (23)

Monday, February 24, 2014 2:18 PM ✅Answered

Hi,

@Jason: On 2008 R2 when I do: %windir%\sysnative\reg.exe. Error "System cannot find the file". Sysnative is only visible from 32-bit apps, I am running this from standard CMD on R2.

@Iain: Our developers have written a .exe that runs slmgr.vbs /skms commands, which I have deployed through a package and even that didn't work. Ran into the same problem.

Thank You


Monday, February 24, 2014 2:26 PM ✅Answered

Right, and the ConfigMgr client agent still runs processes as 32-bit so it will work when launched from there. If you are simply looking to test the command-line/script, then you need to launch it from the 32-bit command processor (cmd.exe) which you can launch from \windows\syswow64.

Jason | http://blog.configmgrftw.com


Tuesday, February 25, 2014 9:46 AM ✅Answered

Change the x64 command to:

%windir%\sysnative\cscript.exe //nologo %windir%\system32\slmgr.vbs /skms:dc4hmancmddc1.mydomain.local


Monday, February 24, 2014 1:07 PM

What happens if you run the script using sysinternals PSEXEC with the -s switch to run it as the system account?

This then simulates the way SCCM will run the command.


Monday, February 24, 2014 1:15 PM

how do I do this? sorry would it be:

psexec -s reg add "hklm\software\microsoft\windows nt\currentversion\softwareprotectionplatform" /f /v "KeyManagementServiceName" /t reg_sz /d "dc4hmancmddc1.mydomain.local"


Monday, February 24, 2014 1:17 PM

Are your servers running in 64bit mode?

If yes then maybe this is a problem of 64bit redirection.

Try with a custom Task Sequence and add a run commande line step.

Run it from the Package and type the related command (the program line) and do not forget to TICK the checkbox "Disable 64bit redirection"


Monday, February 24, 2014 1:21 PM

Save the command to a batch file, then:

  • psexec /s cmd.exe
  • run the batch file

Monday, February 24, 2014 1:23 PM

Hi,

@iain: Running the script with psexec works fine and reg is updated successfully.

@Jeremy: Yes the server is running 2008 R2. I know how to create a custom task sequence but I am sort of confused when you say run it from package?

What about servers that run different 32bit OS? Will I have to split my collection based on OS and have different task sequences or is this problem only affecting 64 bit servers?

Thanks


Monday, February 24, 2014 1:25 PM

Also take a look at this thread regarding 64-Bit Redirection:

Registry key in Wow6432node insted of Software Windows 7x64 - SCCM


Monday, February 24, 2014 1:42 PM

Hi,

Just looking at the logs file, I see this:

<![LOG[Running "C:\Windows\system32\cmd.exe" /c "C:\windows\system32\reg.exe add "hklm\software\microsoft\windows nt\currentversion\softwareprotectionplatform" /f /v "KeyManagementServiceName" /t reg_sz /d "dc4hmancmddc1.osmanage.local" with 32bitLauncher]LOG]!><time="13:06:32.677+00" date="02-24-2014" component="execmgr" context="" type="1" thread="4024" file="scriptexecution.cpp:364">

It is launching it with 32bit launcher. So is this still a problem with 64bit redirection?

The thing is before trying this reg fix I tried several times to run command: slmgr.vbs /skms servername.local via  a packag which executed successfully but again the KMS server wasn't updated. So something tells me this is a different problem?


Monday, February 24, 2014 2:07 PM

Using a task sequence to modify the reg key also hasn't worked. It executes successfully but no change to registry.

Any other ideas?


Monday, February 24, 2014 2:11 PM

Could try it with a vb script instead of a command, Like this

Create a package with source file of the script.


Monday, February 24, 2014 2:12 PM

Yes, 64-bit redirection is still an "issue" that you must address. No, you don't need to put this into a task sequence to solve the issue. You can simply call reg.exe from %windir%\sysnative when running on 64-bit OSes and from %windir%\system32 when running on 32-bit OSes. You can try to encapsulate this within a single batch file (branching based on the OS architecture as in this post: http://eddielublog.blogspot.com/2010/04/batch-file-for-checking-os-architecture.html) or use two programs. With two programs, you can either use two collections or the program requirements to ensure each only runs on the OS architecture that it is applicable to.

Jason | http://blog.configmgrftw.com


Monday, February 24, 2014 2:21 PM

You could also consider using DCM (Desired Configuration Management) for this scenario.


Monday, February 24, 2014 2:41 PM

I am about to try this:

@echo off
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT
cmd /c "%windir%\system32\cscript.exe %windir%\system32\slmgr.vbs /skms dc4hmancmddc1.mydomain.local"
goto END
:64BIT
cmd /c "%windir%\sysnative\cscript.exe "%windir%\sysnative\slmgr.vbs /skms dc4hmancmddc1.mydomain.local"
:END

Lets see if it works this time.

Thanks Guys


Monday, February 24, 2014 3:01 PM

Ok, the above script didn't work. Got the same issue where it executes successfully but the KMS server isn't updated.

If I go to %windir%\syswow64 and launch cmd.exe from there and execute my batch file, it doesn't update the KMS server although it says successfully updated....

This was never a problem in 2007 (I never came across it).

Thank You


Monday, February 24, 2014 4:23 PM

I still encourage you to do this with DCM instead of packages.


Monday, February 24, 2014 4:36 PM

I understand using DCM but why have I got this problem?

I need to get this resolved because I suppose this will haunt me when I am trying to do other things as well.

As a further update, I tried using powershell to accomplish the same task and I ran into the same problem. Script executes successfully but no changes are made.

Thank You


Monday, February 24, 2014 5:52 PM

Other method would also be just by running:

cscript.exe //nologo %windir%\system32\slmgr.vbs /skms:dc4hmancmddc1.mydomain.local

I don't think it matters which slmgr (in system32 or syswow64) you run, because at least in my Windows 7 x64, both files are exactly the same size. Keep it simple, and don't script a script that's already there.


Monday, February 24, 2014 6:15 PM

Hi,

I have tried the above. It does exactly the same thing. It runs successfully but doesnt update the kms server.

If i run the command manually from c:\windows\syswow64\cmd.exe it says successful but no changes occur. If i just start CMD normally and run command it works fine.

Thanks

Mayur


Monday, February 24, 2014 6:31 PM

For the x64:

%windir%\sysnative\cscript.exe //nologo %windir%\sysnative\slmgr.vbs /skms:dc4hmancmddc1.mydomain.local

For the x86:

%windir%\system32\cscript.exe //nologo %windir%\system32\slmgr.vbs /skms:dc4hmancmddc1.mydomain.local

You can also do this with application model if you like, should work out of box. Use the registry value as your detection method. For the application model you should use the x86 command I provided above, it should then use same system32 -folder (sysnative) with both x86 and x64.


Tuesday, February 25, 2014 9:32 AM

Thanks for the above.

I tested the two commands you gave me in c:\windows\syswow64\cmd.exe on windows 2008 R2.

The x64 bit command doesn't work. it comes back with "System cannot find the path specified.

The x86 bit command works fine. So I created a package with a .bat file that executes the x86 command you provided. I get the same problem. Command executes but no changes to the registry.

I hope the above explains the problem I am having.

Thank You


Tuesday, February 25, 2014 10:15 AM

YES! Finally, the above command works via a package and the KMS server is updated as expected.

Thank you for all your help, much appreciated! I need to update the KMS on approx 1000 servers and you have saved me a massive headache!

I also understand the sysnative concept a lot better as I had never come across this. I think I am also going to install x64 client on 64-bit OS going forward, which would help address this issue hopefully.

Thank You very much!!

Mayur