MSFN Forum: How to get an user's Startup folder - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to get an user's Startup folder By using VBScript programming Rate Topic: -----

#1 User is offline   ponghy 

  • MSFN Student
  • PipPip
  • Group: Members
  • Posts: 175
  • Joined: 21-April 05

  Posted 08 November 2005 - 02:18 AM

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 :)

This post has been edited by ponghy: 08 November 2005 - 02:18 AM



#2 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 08 November 2005 - 03:04 PM

Try this VBS script

Quote

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


#3 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,239
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 08 November 2005 - 03:30 PM

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


#4 User is offline   ponghy 

  • MSFN Student
  • PipPip
  • Group: Members
  • Posts: 175
  • Joined: 21-April 05

  Posted 08 November 2005 - 04:52 PM

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:

#5 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 08 November 2005 - 08:18 PM

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

Quote

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


#6 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,239
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 08 November 2005 - 08:34 PM

@ponghy - Strange it works on every machine I've tried it in, both domain and non-domain systems. Sure it's not an issue with your system?

#7 User is offline   ponghy 

  • MSFN Student
  • PipPip
  • Group: Members
  • Posts: 175
  • Joined: 21-April 05

  Posted 09 November 2005 - 02:11 AM

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 ;)

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy