Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update "Last User" in Registry

Status
Not open for further replies.

lakers8175

IS-IT--Management
Sep 18, 2001
67
US
Is there a way to update the "Last User" in the registry to the current NT user ID? The path in the registry is HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Access\Settings\Last User
 
Hello, lakers8175.

Would it be nice if forum knows at least the config of your system, local/remote and the mechanism you want to get it done? Maybe somebody can then help.

regards - tsuji
 
Sorry, I want it changed on the local WINNT (client). I'm dealing with an Access security file and when you first click on the Access MDB, it displays the log on ID from the "Last User" in the registry. Either in VB or DOS, I would like the command to change it(Last User) to the Network ID that the PC is logged onto.

Sean

 
Hello, lakers8175.

Thanks for the feedback.
As nobody yet volunteers, I would post a solution, not without some hesitation.

My hesitation is mainly twofold.
Firstly, as the entry is stored under the branch of HKCU, I have difficulty in seeing why Last User is allowed to change in time. The _only_ possibility, it seems to me, is that the local m/c is allowed to be logged in by a legitimate user. Then, after logged in, the m/c can be used by some other persons who can work on Access using his/her name proper other than the registered user to the network. If that is the case, I of course have no further comment on it.
Second is that I can only conceive a scheme to implement the registry update soon after the user logged in the m/c. He/she may or may not work at all on the Access thereafter. The scheme is conceived to be kept the user from being disturbed as much as possible. So the following script can either be called soon after the login script is run or within it. I have difficulty in integrating it with Access opening itself. This latter scheme would have avoided the conceptual difficulty mentioned above.

In any case, it is all up to your good judgement.

A short comment on the script. It will check if the registry key exists at all. If the key does not exist, one or some of the key(s) in the chain from HKCU to Settings do not exist. If this is detected, a message box will pop up asking for the user to intervene. Otherwise, it will execute in silence. You can of course comment out the message box and set qry to vbYes or vbNo. Then it would proceed in silence and will or will not create the key itself and set the entry accordingly.

That is all what I have to comment upon.

regards - tsuji

'-------DefaultAccessLastUser.vbs----/tsuji/-----
Option Explicit

Const title = "Registry Update"
Const key = "HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Access\Settings"
Const entry = "Last User"

Dim oNet, value, wsh, qry
Set oNet = CreateObject("WScript.Network")
value = oNet.UserName

Set wsh = CreateObject("WScript.Shell")

On Error Resume Next
wsh.RegRead entry
If Err <>0 Then
qry=MsgBox(&quot;Registry key : &quot; & key & &quot; does not exist.&quot; & vbCrLf & _
&quot;If you choose to proceed, the key will be built anew.&quot; & vbCrLf & _
&quot;Do you choose to proceed ?&quot;, vbExclamation+vbYesNo, title)
End If
Err.Clear
On Error GoTo 0

If qry = vbYes Then
wsh.RegWrite key & &quot;\&quot; & entry, value
'---------
'un-Comment this if you prefer intervention from the part of user---which is not preferrable.
'MsgBox &quot;Registry update of entry : &quot; & vbCrLf & _
' key & &quot;\&quot; & entry & &quot; = &quot; & username & vbCrLf & _
' &quot; is successful.&quot;, vbInformation, title
'---------
Else
MsgBox &quot;Registry update is aborted&quot;, vbInformation, title
End If

Set wsh = Nothing
Set oNet = Nothing
WScript.Quit
'-------DefaultAccessLastUser.vbs----/tsuji/-----
 
<<Erratum>>

Upon re-reading what I've posted, I discover that I've messed up a draft with a tested version. Hence, I must repost the script to put the record straight. Here it is.

'-Revised-----DefaultAccessLastUser.vbs----------------/tsuji/--------
Option Explicit

Const title = &quot;Registry Update&quot;
Const key = &quot;HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Access\Settings&quot;
Const entry = &quot;Last User&quot;

Dim oNet, value, wsh, qry
Set oNet = CreateObject(&quot;WScript.Network&quot;)
value = oNet.UserName

Set wsh = CreateObject(&quot;WScript.Shell&quot;)

qry = vbYes
On Error Resume Next
wsh.RegRead entry
If Err <>0 Then
qry=MsgBox(&quot;Registry key : &quot; & key & &quot; does not exist.&quot; & vbCrLf & _
&quot;If you choose to proceed, the key will be built anew.&quot; & vbCrLf & _
&quot;Do you choose to proceed ?&quot;, vbExclamation+vbYesNo, title)
End If
Err.Clear
On Error GoTo 0

If qry = vbYes Then
wsh.RegWrite key & &quot;\&quot; & entry, value, &quot;REG_SZ&quot;
'---------
'un-Comment this if you prefer intervention from the part of user---which is not preferrable.
'MsgBox &quot;Registry update of entry : &quot; & vbCrLf & _
' key & &quot;\&quot; & entry & &quot; = &quot; & value & vbCrLf & _
' &quot; is successful.&quot;, vbInformation, title
'---------
Else
MsgBox &quot;Registry update is aborted&quot;, vbInformation, title
End If

Set wsh = Nothing
Set oNet = Nothing
WScript.Quit
'-Revised-----DefaultAccessLastUser.vbs----------------/tsuji/--------

Sorry for the confusion and thanks for your attention.

- tsuji -


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top