Jump to content

Calling %systemdrive% from the registry?


Recommended Posts

here's the deal:

i am trying to get a RunOnce command into the registry which calls a bat in my OEM share. this works just fine when i specify the drive letter, but it refuses to accept %systemdrive% in the place of C: (or D: or whatever drive). is there an alternate syntax for this? i have a work-around but it's not that great so i figured i'd ask...

Link to comment
Share on other sites


To use environment variables it has to be a REG_EXPAND_SZ key

REG ADD /? will show you as Aaron pointed out and it support's the REG_EXPAND also

REG ADD HKLM\Software\MyCo /v Path /t REG_EXPAND_SZ /d %%systemroot%%

Adds a value (name: Path, type: REG_EXPAND_SZ, data: %systemroot%)

Notice: Use the double percentage ( %% ) inside the expand string

Link to comment
Share on other sites

my way of doing it might be slightly easier, maybe (for me it is, I know nothing about registry editing)...

I have a batch file something like this:

@echo offif %systemdrive% == C: goto :c_driveif %systemdrive% == D: goto _drivegoto :error:c_drivereg /import %systemdrive%\install\imports\c-drive.reggoto :end_drivereg /import %systemdrive%\install\imports\d-drive.reggoto :end:errorecho Silly drive letters like %systemdrive% not supported!:end

so as you can see, I have a similar need as you do of adding entries to the registry that will obviously not be the same if the drive assignment for %systemdrive% is different.... I just have different copies of the registry files that point to different drive letters like above...

I hope this helps a little

Link to comment
Share on other sites

that doesn't work.

this is because %systemdrive% resolves to a drive letter followed by a colon. you cannot have a colon in a filename, so the bat points at a file which doesn't exist, and then your reg file is not imported...

Link to comment
Share on other sites

Crusher,Apr 18 2004, 09:22 PM]hmm.. i just thought of an easier way
@echo off

reg /import %systemdrive%-drive.reg

This will work:

reg /import %systemdrive:~0,1%-drive.reg

Syntax (see set /?):

%variable:~[+-]offset,[+-]# of characters%
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...