I'm trying to modify a registry key in HKLM to receive the value of the
currently logged on user (%username%). I need this to run as part of the
normal user logon script...whether it is embedded in the current script or
called separately. My logon script is simply a *.bat file that synchronizes
the time, maps some drives and copies files to the local machine. I'm not a
scripter so I tried Scriptomatic and Tweakomatic with similar (negative)
results. The key in question is a string value. I'm running a W2K3 domain if
this matters. Thanks!

Re: logon script, username and registry edit by rwh

rwh
Mon Sep 12 14:01:38 CDT 2005

see my article posted at
http://www.rodharrison.com/DOS_Stuff/run_registry.htm
this will explain how to call a .reg file through a batch script.


RE: logon script, username and registry edit by Kendoh

Kendoh
Mon Sep 12 14:43:03 CDT 2005

the following will create a Reg string value in a key called "Logged in User"
under software HKLM. You can modify those portions as needed. A quick note,
the logged in user will be stored as "domain\username". You can parse out the
domain\ if you wanted to.

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strKeyPath = "SOFTWARE\Logged on User"
strValueName = "User Name"

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:stdRegProv")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
strValue = objComputer.UserName

objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName, strValue
Next


"Mark R." wrote:

> I'm trying to modify a registry key in HKLM to receive the value of the
> currently logged on user (%username%). I need this to run as part of the
> normal user logon script...whether it is embedded in the current script or
> called separately. My logon script is simply a *.bat file that synchronizes
> the time, maps some drives and copies files to the local machine. I'm not a
> scripter so I tried Scriptomatic and Tweakomatic with similar (negative)
> results. The key in question is a string value. I'm running a W2K3 domain if
> this matters. Thanks!

RE: logon script, username and registry edit by Kendoh

Kendoh
Mon Sep 12 14:49:05 CDT 2005

By they way, this is a vbscript, as you posted into a vbscript forum. You can
call this from your bat file.

"Kendoh" wrote:

> the following will create a Reg string value in a key called "Logged in User"
> under software HKLM. You can modify those portions as needed. A quick note,
> the logged in user will be stored as "domain\username". You can parse out the
> domain\ if you wanted to.
>
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> strComputer = "."
> strKeyPath = "SOFTWARE\Logged on User"
> strValueName = "User Name"
>
> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:stdRegProv")
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> strValue = objComputer.UserName
>
> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName, strValue
> Next
>
>
> "Mark R." wrote:
>
> > I'm trying to modify a registry key in HKLM to receive the value of the
> > currently logged on user (%username%). I need this to run as part of the
> > normal user logon script...whether it is embedded in the current script or
> > called separately. My logon script is simply a *.bat file that synchronizes
> > the time, maps some drives and copies files to the local machine. I'm not a
> > scripter so I tried Scriptomatic and Tweakomatic with similar (negative)
> > results. The key in question is a string value. I'm running a W2K3 domain if
> > this matters. Thanks!

Re: logon script, username and registry edit by MarkR

MarkR
Mon Sep 12 15:41:05 CDT 2005

Thanks for the reply. I've used that line before but it was with static
registry entries. This key will be dependent on the %username% variable as
user login to the domain.

"rwh@rodharrison.com" wrote:

> see my article posted at
> http://www.rodharrison.com/DOS_Stuff/run_registry.htm
> this will explain how to call a .reg file through a batch script.
>
>

RE: logon script, username and registry edit by MarkR

MarkR
Mon Sep 12 15:44:09 CDT 2005

how best to "parse out" the domain portion?

"Kendoh" wrote:

> the following will create a Reg string value in a key called "Logged in User"
> under software HKLM. You can modify those portions as needed. A quick note,
> the logged in user will be stored as "domain\username". You can parse out the
> domain\ if you wanted to.
>
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> strComputer = "."
> strKeyPath = "SOFTWARE\Logged on User"
> strValueName = "User Name"
>
> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:stdRegProv")
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> strValue = objComputer.UserName
>
> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName, strValue
> Next
>
>
> "Mark R." wrote:
>
> > I'm trying to modify a registry key in HKLM to receive the value of the
> > currently logged on user (%username%). I need this to run as part of the
> > normal user logon script...whether it is embedded in the current script or
> > called separately. My logon script is simply a *.bat file that synchronizes
> > the time, maps some drives and copies files to the local machine. I'm not a
> > scripter so I tried Scriptomatic and Tweakomatic with similar (negative)
> > results. The key in question is a string value. I'm running a W2K3 domain if
> > this matters. Thanks!

Re: logon script, username and registry edit by Greg

Greg
Mon Sep 12 16:04:21 CDT 2005

This is a quick and dirty way

strValueName = "DOMAIN\User Name"
strValueName = right(StrValueName,len(StrValueName)-7)

I set it to 7 because DOMAIN\ has 7 characters. Adjust for the length of
your domain name

Also, if you have more than one domain, you should search for the "\" each
time and do a dynamic calculation.



"Mark R." <MarkR@discussions.microsoft.com> wrote in message
news:CB50B41D-AE2D-4F28-AA1C-54D280339299@microsoft.com...
> how best to "parse out" the domain portion?
>
> "Kendoh" wrote:
>
>> the following will create a Reg string value in a key called "Logged in
>> User"
>> under software HKLM. You can modify those portions as needed. A quick
>> note,
>> the logged in user will be stored as "domain\username". You can parse out
>> the
>> domain\ if you wanted to.
>>
>> Const HKEY_LOCAL_MACHINE = &H80000002
>>
>> strComputer = "."
>> strKeyPath = "SOFTWARE\Logged on User"
>> strValueName = "User Name"
>>
>> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
>> strComputer & "\root\default:stdRegProv")
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\" _
>> & strComputer & "\root\cimv2")
>>
>> Set colComputer = objWMIService.ExecQuery _
>> ("Select * from Win32_ComputerSystem")
>>
>> For Each objComputer in colComputer
>> strValue = objComputer.UserName
>>
>> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName,
>> strValue
>> Next
>>
>>
>> "Mark R." wrote:
>>
>> > I'm trying to modify a registry key in HKLM to receive the value of the
>> > currently logged on user (%username%). I need this to run as part of
>> > the
>> > normal user logon script...whether it is embedded in the current script
>> > or
>> > called separately. My logon script is simply a *.bat file that
>> > synchronizes
>> > the time, maps some drives and copies files to the local machine. I'm
>> > not a
>> > scripter so I tried Scriptomatic and Tweakomatic with similar
>> > (negative)
>> > results. The key in question is a string value. I'm running a W2K3
>> > domain if
>> > this matters. Thanks!



Re: logon script, username and registry edit by Kendoh

Kendoh
Mon Sep 12 16:29:01 CDT 2005

This will work for any domain...

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strKeyPath = "SOFTWARE\Logged on User"
strValueName = "User Name"

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:stdRegProv")

objReg.CreateKey HKEY_LOCAL_MACHINE, strKeyPath

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
strValue = objComputer.UserName
stringlength = len(strValue)
charnumber = InStrRev(strValue, "\")
strValue = right(strValue,stringlength-charnumber)
objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName, strValue
Next


"Greg Herzog" wrote:

> This is a quick and dirty way
>
> strValueName = "DOMAIN\User Name"
> strValueName = right(StrValueName,len(StrValueName)-7)
>
> I set it to 7 because DOMAIN\ has 7 characters. Adjust for the length of
> your domain name
>
> Also, if you have more than one domain, you should search for the "\" each
> time and do a dynamic calculation.
>
>
>
> "Mark R." <MarkR@discussions.microsoft.com> wrote in message
> news:CB50B41D-AE2D-4F28-AA1C-54D280339299@microsoft.com...
> > how best to "parse out" the domain portion?
> >
> > "Kendoh" wrote:
> >
> >> the following will create a Reg string value in a key called "Logged in
> >> User"
> >> under software HKLM. You can modify those portions as needed. A quick
> >> note,
> >> the logged in user will be stored as "domain\username". You can parse out
> >> the
> >> domain\ if you wanted to.
> >>
> >> Const HKEY_LOCAL_MACHINE = &H80000002
> >>
> >> strComputer = "."
> >> strKeyPath = "SOFTWARE\Logged on User"
> >> strValueName = "User Name"
> >>
> >> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> >> strComputer & "\root\default:stdRegProv")
> >>
> >> Set objWMIService = GetObject("winmgmts:" _
> >> & "{impersonationLevel=impersonate}!\\" _
> >> & strComputer & "\root\cimv2")
> >>
> >> Set colComputer = objWMIService.ExecQuery _
> >> ("Select * from Win32_ComputerSystem")
> >>
> >> For Each objComputer in colComputer
> >> strValue = objComputer.UserName
> >>
> >> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName,
> >> strValue
> >> Next
> >>
> >>
> >> "Mark R." wrote:
> >>
> >> > I'm trying to modify a registry key in HKLM to receive the value of the
> >> > currently logged on user (%username%). I need this to run as part of
> >> > the
> >> > normal user logon script...whether it is embedded in the current script
> >> > or
> >> > called separately. My logon script is simply a *.bat file that
> >> > synchronizes
> >> > the time, maps some drives and copies files to the local machine. I'm
> >> > not a
> >> > scripter so I tried Scriptomatic and Tweakomatic with similar
> >> > (negative)
> >> > results. The key in question is a string value. I'm running a W2K3
> >> > domain if
> >> > this matters. Thanks!
>
>
>

Re: logon script, username and registry edit by MarkR

MarkR
Mon Sep 12 21:52:02 CDT 2005

this worked perfectly...thanks for the assistance!

Mark

"Kendoh" wrote:

> This will work for any domain...
>
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> strComputer = "."
> strKeyPath = "SOFTWARE\Logged on User"
> strValueName = "User Name"
>
> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:stdRegProv")
>
> objReg.CreateKey HKEY_LOCAL_MACHINE, strKeyPath
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> strValue = objComputer.UserName
> stringlength = len(strValue)
> charnumber = InStrRev(strValue, "\")
> strValue = right(strValue,stringlength-charnumber)
> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName, strValue
> Next
>
>
> "Greg Herzog" wrote:
>
> > This is a quick and dirty way
> >
> > strValueName = "DOMAIN\User Name"
> > strValueName = right(StrValueName,len(StrValueName)-7)
> >
> > I set it to 7 because DOMAIN\ has 7 characters. Adjust for the length of
> > your domain name
> >
> > Also, if you have more than one domain, you should search for the "\" each
> > time and do a dynamic calculation.
> >
> >
> >
> > "Mark R." <MarkR@discussions.microsoft.com> wrote in message
> > news:CB50B41D-AE2D-4F28-AA1C-54D280339299@microsoft.com...
> > > how best to "parse out" the domain portion?
> > >
> > > "Kendoh" wrote:
> > >
> > >> the following will create a Reg string value in a key called "Logged in
> > >> User"
> > >> under software HKLM. You can modify those portions as needed. A quick
> > >> note,
> > >> the logged in user will be stored as "domain\username". You can parse out
> > >> the
> > >> domain\ if you wanted to.
> > >>
> > >> Const HKEY_LOCAL_MACHINE = &H80000002
> > >>
> > >> strComputer = "."
> > >> strKeyPath = "SOFTWARE\Logged on User"
> > >> strValueName = "User Name"
> > >>
> > >> Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> > >> strComputer & "\root\default:stdRegProv")
> > >>
> > >> Set objWMIService = GetObject("winmgmts:" _
> > >> & "{impersonationLevel=impersonate}!\\" _
> > >> & strComputer & "\root\cimv2")
> > >>
> > >> Set colComputer = objWMIService.ExecQuery _
> > >> ("Select * from Win32_ComputerSystem")
> > >>
> > >> For Each objComputer in colComputer
> > >> strValue = objComputer.UserName
> > >>
> > >> objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, StrValueName,
> > >> strValue
> > >> Next
> > >>
> > >>
> > >> "Mark R." wrote:
> > >>
> > >> > I'm trying to modify a registry key in HKLM to receive the value of the
> > >> > currently logged on user (%username%). I need this to run as part of
> > >> > the
> > >> > normal user logon script...whether it is embedded in the current script
> > >> > or
> > >> > called separately. My logon script is simply a *.bat file that
> > >> > synchronizes
> > >> > the time, maps some drives and copies files to the local machine. I'm
> > >> > not a
> > >> > scripter so I tried Scriptomatic and Tweakomatic with similar
> > >> > (negative)
> > >> > results. The key in question is a string value. I'm running a W2K3
> > >> > domain if
> > >> > this matters. Thanks!
> >
> >
> >