2

See http://technet.microsoft.com/en-us/library/ff715408.aspx for FirstLogonCommand, how do I specify a CommandLine for the OS boot drive and not just use "C:" like the examples do. The OS boot drive might not be "C:".

Update: I am using C++ to write the XML and the program that will run is also written in C++.

unixman83
  • 1,932
  • 8
  • 25
  • 33
  • I am not entirely sure what you are after (I am not a Windows person), but the `%SystemDrive%` environment variable is set to the operating system drive, and should work in most commands. – cyberx86 Feb 18 '12 at 08:23
  • @unixman83: I didn't downvote, but please see my answer. This is not really a script-question. This is about running post-install commands during an automated install of Vista and later Windows versions. – Tonny Feb 18 '12 at 09:42
  • @Tonny, the OP didn't ask about scripting, so I don't understand why you keep mentioning it. Regardless, the environment variables will be expanded as required at this point. – John Gardeniers Feb 18 '12 at 10:50
  • 1
    @John Gardeniers: That they are expended at that point may be obvious to you, but I have never been able to get that confirmed anywhere. As for the scripting... What I intended to say, but didn't formulate well enough, is that when you pass unexpanded env-var's from one program to another (as happens here) it totally depends on the programs/environment whether or not they will be expanded. – Tonny Feb 18 '12 at 11:39
  • @Tony, any command passed top cmd.exe will have environment variables expanded. – John Gardeniers Feb 19 '12 at 20:39
  • @JohnGardeniers: not all software runs commands by passing them to cmd.exe. – Harry Johnston Feb 21 '12 at 03:30
  • 1
    @Harry, while that is perfectly true, my comment was was made in the context of the question being asked here, in which instance cmd.exe *is* involved. – John Gardeniers Feb 21 '12 at 04:24
  • 1
    @JohnGardeniers: I believe you, but I think Tonny is asking for a reference. That is, how do you know that the FirstLogonCommand option uses cmd.exe? – Harry Johnston Feb 21 '12 at 21:27

2 Answers2

1

The %SystemDrive% environment variable is set to the operating system drive in Windows and can be replaced into most commands.

cyberx86
  • 20,805
  • 1
  • 62
  • 81
1

Interesting question. No help from Microsoft (as usual).

%SystemDrive% environment var is normally what you would use in scripts and such, but this is not really a script.

Frankly I have no idea if it will work in this particular fringe case.

If the system passes whatever is in the XML straight to cmd.exe it will work.

If it goes, with out expanding the environment var, directly into the exec() call of the Windows-API it is doubtful it will work.

You will just have to try it. As there is no visual feedback while this runs I recommend you run something that writes a logfile in a known location so you can be certain whether it worked or not.

Another solution comes to mind: Assuming that, while this runs, the current drive IS the OS drive you might just get away without specifying the drive at all. Just use the full part from the top of the drive without the drive-letter and colon.

E.g: \synccommands\run1.exe

Let us know how this turned out. I for one am interested if one of those solutions works and I don't have the time nor the equipment to experiment myself.

Tonny
  • 6,332
  • 1
  • 18
  • 31
  • 1
    If Windows Setup doesn't expand environment variables, just explicitly invoke cmd.exe: cmd /c %SystemDrive%\path\program.exe – Harry Johnston Feb 21 '12 at 03:31