Click to See Complete Forum and Search --> : VBScript to get Windows Directory?


koden
October 25th, 2005, 04:34 PM
How do I get the window's directory using VBScript? Here's how I get the Program Files Directory:

Function GetProgramsFolder()
Dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")
GetProgramsFolder = wshShell.SpecialFolders("AllUsersPrograms")
End Function

mmetzger
October 25th, 2005, 05:15 PM
Try this:


set shell = WScript.CreateObject("WScript.Shell")

windowsdir = shell.ExpandEnvironmentStrings("%windir%")

MsgBox(windowsdir)

koden
October 31st, 2005, 06:29 PM
How about the system windows directory?

for example: when you're in a machine with Terminal Services, I want the system windows directory rather than C:\Documents and Settings\Adminstrator\WINDIR

thanks!

PeejAvery
November 1st, 2005, 12:08 AM
%windir% is a constant. How did it load the profile WINDOWS folder?

koden
November 1st, 2005, 01:04 PM
anyone know how to get the SYSTEM windows directory? I need this in the case where there are multiple users in a terminal services enabled machine.

mmetzger
November 1st, 2005, 02:01 PM
Open a command prompt and type "set" and press enter. This will show you all the current environment variables. Find the one you need and use it accordingly.

koden
November 2nd, 2005, 12:48 PM
Open a command prompt and type "set" and press enter. This will show you all the current environment variables. Find the one you need and use it accordingly.

I need to program this dynamically, so that anyone running my vbscript will have their system's windows directory path available.

please help!

mmetzger
November 2nd, 2005, 12:59 PM
I need to program this dynamically, so that anyone running my vbscript will have their system's windows directory path available.

please help!

I don't understand what you're asking. Every user has environment variables configured. If the %windir% one does not work for what you need, login as one of said users and then type "set". This will show you all available variables. Find the one that works and use that in your vbscript.

PeejAvery
November 2nd, 2005, 01:38 PM
Okay, taking mmetzger's original thought. Change "%windir" to "%WindDir%"

set shell = CreateObject("WScript.Shell")
WScript.Echo shell.ExpandEnvironmentStrings("%WinDir%")

koden
November 2nd, 2005, 03:20 PM
I don't understand what you're asking. Every user has environment variables configured. If the %windir% one does not work for what you need, login as one of said users and then type "set". This will show you all available variables. Find the one that works and use that in your vbscript.


I'm writing a program using vbscript. It will be distributed to thousands of different machines. It needs to find the System's windows directory (C:\WINDOWS or C:\WINNT), not a users' directory (ie. C:\Documents and Settings\Administrator\Windows). Currently %windir% finds the user's windows directory.

I cannot simply goto every computer and login different and type set. This needs to be dynamically discovered.

Does %WinDir% get the system windows directory?

This is only an issue on Terminal Services machines, though about 900 of the thousands will be terminal service enabled machines.

mmetzger
November 2nd, 2005, 03:46 PM
Sigh...

I'm not suggesting you to try it on every machine, but try it on one of the ones you expect to have issues.

That being said, try %SystemRoot%.

PeejAvery
November 2nd, 2005, 04:18 PM
Does %WinDir% get the system windows directory?
You keep saying "system windows" directory.

There is only one windows directory (c:\windows\).
%windir%
There is only one system directory (c:\windows\system32).
%systemdir%
There is only one windows profile per user (c:\Documents and Settings\User\windows).
There is only one system profile per user (c:\Documents and Settings\User\windows\system32).

Both %windir% and %systemdir% are variables usually, but not always, set by Windows. If they are set, you can call them. If they are not, you cannot. It is rare that they will not work.

koden
November 9th, 2005, 02:40 PM
I don't think anyone understands.

This is not a problem on any specific machine. This is a product that is going out to thousands of customers with different machines. My vbscript needs to goto the C:\WINNT or C:\Windows or equivalent on their machines, even in terminal service enabled machines.

%windir% goes to C:\WINNT or C:\WINDOWS etc. if it's not terminal service enabled. If it IS terminal service enambed, it will goto the .../User/Windows directory. I need to find a specific file that is NEVER in the /user/windows directory, but ALWAYS in the C:\WINNT or C:\WINDOWS type folder.

In C++ this can be found using GetSystemWindowsDirectory(). GetWindowsDirectory will get the /user/windows if under terminal services, much like %windir%. So what is the equivalent of GetSystemWIndowsDirectory() in c++?

mmetzger: you're totally missing the point. I've tried it on different machines, and I know for a fact that it is not getting the correct directory in terminal service enabled machines. This is a product that will be distributed to thousands of people, VERY dynamic and unpredictable. I NEED to be sure it will not fail under any circumstance. This is not some small little script I'm running on a little website or something.

mmetzger
November 9th, 2005, 02:57 PM
I understand the fact this is not on a single machine. What you don't seem to understand is that there are multiple variables that point to the same directory. I do not have access to a terminal server system to validate this, but on XP, 2000 and 2003 SystemRoot points to the directory you're looking for. What I want to know however is if there is a different variable on a terminal server login that points to it. Hence the reason I was telling you to run "set" and determine that. If that is the case, you simply check for the existence of it first. If you find it then use it, otherwise check windir, systemroot, etc.

koden
November 10th, 2005, 03:10 PM
I understand the fact this is not on a single machine. What you don't seem to understand is that there are multiple variables that point to the same directory. I do not have access to a terminal server system to validate this, but on XP, 2000 and 2003 SystemRoot points to the directory you're looking for. What I want to know however is if there is a different variable on a terminal server login that points to it. Hence the reason I was telling you to run "set" and determine that. If that is the case, you simply check for the existence of it first. If you find it then use it, otherwise check windir, systemroot, etc.

ah i see what you mean. totally didn't understand the first couple times =P