windoes system directoty?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Dear all,

I thought there was an easy way to get the windows system
directory but I can't find it.

Anybody an idea?

Thanks,

JOhn
 
Thanks Bill for your quick reply,really appreciated.
However... I am not sure how to use and can't find help on
it.

I am trying to replace the "c:\winnt\" in the following
code so help will always be found no matter where my xla
is called from:

Sub ShwHelp()
Application.Help "C:\WINNT\TPBQ.CHM"
'%windir%
End Sub

Any idea?

Thanks for your help.

John
 
In Excel XP, I can do the following....

Sub Demo()
Dim s
s = Application.OperatingSystem ' If you want to test
s = CreateObject("Scripting.FileSystemObject").GetSpecialFolder(0)
Debug.Print s
End Sub

Returns...
C:\WINDOWS
 
In a command window you can do

Echo %windir%
and it returns
C:\Winnt
on my system. Not sure how you would use it in VBA

You can check the comspec environment variable

? environ("comspec")
C:\WINNT\system32\cmd.exe

or
? environ("windir")
C:\WINNT

I am on Win 2K and I can't guarantee that these environ variables will be
defined on every OS version.

Other methods:

http://support.microsoft.com/default.aspx?scid=kb;en-us;170728
OFF97: Macro to Get Windows and Windows System Directories

http://support.microsoft.com/default.aspx?scid=kb;en-us;213496
XL2000: Macros to Return Windows and System Directory Paths

http://support.microsoft.com/default.aspx?scid=kb;en-us;108278
XL: Macros to Return Windows and System Directory Paths
 
Harald,

Just continuing the line Tom started really, but personally I would use the
method that Dana proposed. I don't have a 9x system to hand to test it, but
I would be surprised if that failed to work on them.

Regards

Bob
 
Just another test:
Windows 98 SE

? environ("comspec")
C:\WINDOWS\COMMAND.COM
? environ("windir")
C:\WINDOWS


Comspec has been valid since DOS 1.x or there about. I don't know about
windir

As to Dana's suggestion, no guarantee that the scripting runtime is present
although I expect it would be in most cases.
It worked in Windows 98 SE. The API would work in all 32 bit versions I
would think.


Regards,
Tom Ogilvy
 
But I'd think that
either C:\WINDOWS\SYSTEM or C:\WINDOWS\SYSTEM32 would be my "windows
system directoty" :-)

True, but it should only be one step down.

I would go with the API which I provided links to KB articles showing how
in my original post.

Regards,
Tom Ogilvy
 
Back
Top