Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - find local profile path on XP

Reply
 
Old 05-05-2009   #1 (permalink)
Chris


 
 

find local profile path on XP

Our users are using roaming profile. Using the login script I want to copy a
file to a folder under their local profile on XP machine. However, I found
it's not always under
c:\document and settings\<username>\

instead many of them are actuall at

c:\document and settings\<username.domain>\

How can I make login script detect the correct path?

Is there a variable I can use in login script so it will check the current
path during logon? Or a variable I can use in the copy command to the
current path?

Thanks.

My System SpecsSystem Spec
Old 05-05-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: find local profile path on XP


You can use %homedrive%\%homepath% and expand it using WScript.Shell's
ExpandEnvironmentStrings method, like this, to get the user's root folder:

dim WshShell: Set WshShell = CreateObject("WScript.Shell")
userRoot = WshShell.ExpandEnvironmentStrings("%homedrive%%homepath%")


However, this may NOT be what you really want. Is there a specific location
under their home folders that you're after? There are other ways to get
specific special folders using Shell.Application that may be preferable.
There are special constants that refer to particular folders, and you can
get the folder's path using the NameSpace method of Shell.Application. For
instance, the value 5 is used for the personal My Documents folder and 16 is
used for the personal Desktop folder. So whatever the actual customizations
or language settings in effect on the system, the following code would
capture the true My Documents and Desktop paths:

Dim sa: Set sa = CreateObject("Shell.Application")
MyDocsPath = sa.Namespace(5).Self.Path
WScript.Echo MyDocsPath
MyDesktopPath = sa.Namespace(16).Self.Path
WScript.Echo MyDesktopPath





"Chris" <Chris@xxxxxx> wrote in message
news0FD1056-7A5F-4F85-8071-76756D813D01@xxxxxx
Quote:

> Our users are using roaming profile. Using the login script I want to
> copy a
> file to a folder under their local profile on XP machine. However, I
> found
> it's not always under
> c:\document and settings\<username>\
>
> instead many of them are actuall at
>
> c:\document and settings\<username.domain>\
>
> How can I make login script detect the correct path?
>
> Is there a variable I can use in login script so it will check the current
> path during logon? Or a variable I can use in the copy command to the
> current path?
>
> Thanks.
My System SpecsSystem Spec
Old 05-05-2009   #3 (permalink)
Chris


 
 

Re: find local profile path on XP

The actually folder I want to copy file to is:

C:\Documents and Setting\<UserNameHere>\Application Data\Microsoft\Signatures

But the problem is that <username> can be either <username> or
<username.domain>.

The variable %homedrive%\%homepath% you mentioned is for home directory, not
the profile path on the desktop, right?

"Alex K. Angelopoulos" wrote:
Quote:

>
> You can use %homedrive%\%homepath% and expand it using WScript.Shell's
> ExpandEnvironmentStrings method, like this, to get the user's root folder:
>
> dim WshShell: Set WshShell = CreateObject("WScript.Shell")
> userRoot = WshShell.ExpandEnvironmentStrings("%homedrive%%homepath%")
>
>
> However, this may NOT be what you really want. Is there a specific location
> under their home folders that you're after? There are other ways to get
> specific special folders using Shell.Application that may be preferable.
> There are special constants that refer to particular folders, and you can
> get the folder's path using the NameSpace method of Shell.Application. For
> instance, the value 5 is used for the personal My Documents folder and 16 is
> used for the personal Desktop folder. So whatever the actual customizations
> or language settings in effect on the system, the following code would
> capture the true My Documents and Desktop paths:
>
> Dim sa: Set sa = CreateObject("Shell.Application")
> MyDocsPath = sa.Namespace(5).Self.Path
> WScript.Echo MyDocsPath
> MyDesktopPath = sa.Namespace(16).Self.Path
> WScript.Echo MyDesktopPath
>
>
>
>
>
> "Chris" <Chris@xxxxxx> wrote in message
> news0FD1056-7A5F-4F85-8071-76756D813D01@xxxxxx
Quote:

> > Our users are using roaming profile. Using the login script I want to
> > copy a
> > file to a folder under their local profile on XP machine. However, I
> > found
> > it's not always under
> > c:\document and settings\<username>\
> >
> > instead many of them are actuall at
> >
> > c:\document and settings\<username.domain>\
> >
> > How can I make login script detect the correct path?
> >
> > Is there a variable I can use in login script so it will check the current
> > path during logon? Or a variable I can use in the copy command to the
> > current path?
> >
> > Thanks.
>
>
My System SpecsSystem Spec
Old 05-05-2009   #4 (permalink)
Chris


 
 

Re: find local profile path on XP

Alex,
I tried your 2nd script and I could use it. Just need to know what the
values are for namespace. Is there one for signatures folder?

"Alex K. Angelopoulos" wrote:
Quote:

>
> You can use %homedrive%\%homepath% and expand it using WScript.Shell's
> ExpandEnvironmentStrings method, like this, to get the user's root folder:
>
> dim WshShell: Set WshShell = CreateObject("WScript.Shell")
> userRoot = WshShell.ExpandEnvironmentStrings("%homedrive%%homepath%")
>
>
> However, this may NOT be what you really want. Is there a specific location
> under their home folders that you're after? There are other ways to get
> specific special folders using Shell.Application that may be preferable.
> There are special constants that refer to particular folders, and you can
> get the folder's path using the NameSpace method of Shell.Application. For
> instance, the value 5 is used for the personal My Documents folder and 16 is
> used for the personal Desktop folder. So whatever the actual customizations
> or language settings in effect on the system, the following code would
> capture the true My Documents and Desktop paths:
>
> Dim sa: Set sa = CreateObject("Shell.Application")
> MyDocsPath = sa.Namespace(5).Self.Path
> WScript.Echo MyDocsPath
> MyDesktopPath = sa.Namespace(16).Self.Path
> WScript.Echo MyDesktopPath
>
>
>
>
>
> "Chris" <Chris@xxxxxx> wrote in message
> news0FD1056-7A5F-4F85-8071-76756D813D01@xxxxxx
Quote:

> > Our users are using roaming profile. Using the login script I want to
> > copy a
> > file to a folder under their local profile on XP machine. However, I
> > found
> > it's not always under
> > c:\document and settings\<username>\
> >
> > instead many of them are actuall at
> >
> > c:\document and settings\<username.domain>\
> >
> > How can I make login script detect the correct path?
> >
> > Is there a variable I can use in login script so it will check the current
> > path during logon? Or a variable I can use in the copy command to the
> > current path?
> >
> > Thanks.
>
>
My System SpecsSystem Spec
Old 05-05-2009   #5 (permalink)
Alex K. Angelopoulos


 
 

Re: find local profile path on XP

"Chris" <Chris@xxxxxx> wrote in message
news:A00A7710-2DFF-4541-A607-D6E23A43EADD@xxxxxx
Quote:

> Alex,
> I tried your 2nd script and I could use it. Just need to know what the
> values are for namespace. Is there one for signatures folder?
Not for that specific folder; the numeric IDs are only for selected standard
operating system folders, not folders they may contain. That's _probably_
sufficient, because you can construct the path to Microsoft\Signatures from
the roaming appdata folder like this:

sigpath = sa.Namespace(5).Self.Path & "\Microsoft\Signatures"

There _may_ be a problem with this if the location of the Signatures folder
is ever customized; there is a value named Signatures in the registry under
the key HKCU\Software\Microsoft\Office\<version# - 11.0, 12.0,
etc>\Common\General

If this is never changed - and probably it's not - you're fine. If this does
get customized, it's also possible to make the code more robust to handle
it, but I'm not sure about what shows up there when it IS customized. I
would suggest that using the technique above will probably do what you want
unless you ever start explicitly redirecting that folder.


Quote:

> "Alex K. Angelopoulos" wrote:
>
Quote:

>>
>> You can use %homedrive%\%homepath% and expand it using WScript.Shell's
>> ExpandEnvironmentStrings method, like this, to get the user's root
>> folder:
>>
>> dim WshShell: Set WshShell = CreateObject("WScript.Shell")
>> userRoot = WshShell.ExpandEnvironmentStrings("%homedrive%%homepath%")
>>
>>
>> However, this may NOT be what you really want. Is there a specific
>> location
>> under their home folders that you're after? There are other ways to get
>> specific special folders using Shell.Application that may be preferable.
>> There are special constants that refer to particular folders, and you can
>> get the folder's path using the NameSpace method of Shell.Application.
>> For
>> instance, the value 5 is used for the personal My Documents folder and 16
>> is
>> used for the personal Desktop folder. So whatever the actual
>> customizations
>> or language settings in effect on the system, the following code would
>> capture the true My Documents and Desktop paths:
>>
>> Dim sa: Set sa = CreateObject("Shell.Application")
>> MyDocsPath = sa.Namespace(5).Self.Path
>> WScript.Echo MyDocsPath
>> MyDesktopPath = sa.Namespace(16).Self.Path
>> WScript.Echo MyDesktopPath
>>
>>
>>
>>
>>
>> "Chris" <Chris@xxxxxx> wrote in message
>> news0FD1056-7A5F-4F85-8071-76756D813D01@xxxxxx
Quote:

>> > Our users are using roaming profile. Using the login script I want to
>> > copy a
>> > file to a folder under their local profile on XP machine. However, I
>> > found
>> > it's not always under
>> > c:\document and settings\<username>\
>> >
>> > instead many of them are actuall at
>> >
>> > c:\document and settings\<username.domain>\
>> >
>> > How can I make login script detect the correct path?
>> >
>> > Is there a variable I can use in login script so it will check the
>> > current
>> > path during logon? Or a variable I can use in the copy command to the
>> > current path?
>> >
>> > Thanks.
>>
>>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Issue with $profile being set to d:\\path... PowerShell
Copy Local Profile to new Domain Profile Vista General
Windows cannot find the local profile and is logging you on with a temporary profile. Changes you make to this profile will be lost when you log off. Vista General
Local profile not found, logged on with a temporary profile Vista account administration
Profile Path Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46