Jump to content

How to get an user's Startup folder


Recommended Posts

Hi! I'm programming an VBScript and I have found the following problem:

I don't know how to get what is the Startup folder of an user other than the current logged on. That is, If I use the SpecialFolders("Startup") Property of WshShell class, I get the the Startup folder for the current user, not for a specified user.

Note I'm getting this information on the T-9 Phase of Windows Setup, therefore I have another handicap: The UserDomain Property of WshNetwork class don't work. I did the following:

Set useracc = GetObject( _
"winmgmts:\root\cimv2:Win32_UserAccount.Domain='" & _
CreateObject("WScript.Network").UserDomain & "',Name='" & SPECIFIED_USER & _
"'" _
)

But I have a Run-Time error. The UserDomain Property returns a Null string (can't find the user domain).

I used the Win32_UserAccount class in order to get the user's SID. With his SID, I could access to the corresponding Registry key to query his Startup Folder:

' Get the Startup folder of SPECIFIED_USER by using his SID.
x = .RegRead( _
"HKEY_USERS\" & useracc.SID & "\Software\Microsoft\Windows\CurrentVersion" & _
"\Explorer\Shell Folders\Startup" _
)

But the previous code don't work because the first snippet is unable to get the User's SID.

Any idea to workaround this? Is necessary to get the User's SID or is there an easier way? ONLY I want to get the Startup folder for SPECIFIED_USER.

Thanks very much for your help :)

Edited by ponghy
Link to comment
Share on other sites


Try this VBS script

Const ALL_USERS_STARTUP = &H18&

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace(ALL_USERS_STARTUP)

Set objFolderItem = objFolder.Self

Wscript.Echo objFolderItem.Path

Set colItems = objFolder.Items

For Each objItem in colItems

Wscript.Echo objItem.Name

Next

Link to comment
Share on other sites

that will work if you are after the startup folder for the All Users profile, for a specific user who is not logged in try this

SPECIFIED_USER="UserID"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set WshShell = WScript.CreateObject("WScript.Shell")

Set objAccount = objWMIService.Get ("Win32_UserAccount.Name='" & SPECIFIED_USER & "',Domain='" & CreateObject("WScript.Network").UserDomain & "'")

x=wshshell.regread("HKEY_USERS\" & objAccount.SID & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Startup")
wscript.echo x

Link to comment
Share on other sites

Thanks for your replies. IcemanND: Your code dind't work :( The problem is the UserDomain property: this is Null when Installing Windows :blink:

Any other way to solve this? Another class? I believe this is possible :unsure:

Link to comment
Share on other sites

Here a VBS script that list all local user on the computer try and mod it to your needs.

Set objDomain = GetObject("WinNT://PLACE_COMPUTER_NAME_HERE")

objDomain.Filter = Array("User")

For Each objUser in objDomain

Wscript.Echo "User name: " & objUser.Name

Wscript.Echo "Description: " & objUser.Description

Wscript.Echo "Logon script path: " & objUser.LoginScript

Wscript.Echo

Next

Link to comment
Share on other sites

Nope, I think so... Anyway, I've found another way in a higher level to solve this problem with the IADs Interface (Active Directory Services Interface).

But, I don't know how to use... I see on the Microsoft reference page (here).

Can you provide me an example? The HomeDirectory property of this class sounds very good... :)

TIA ;)

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...