Jump to content

Recommended Posts

Posted

This one has bugged me for a long time but ive finally stolen someone elses code :) Sorry I cannot give credit as I have no idea who made it.

This is useful under the following scenario:

 

Staff use spreadsheets as 'databases'

Staff1 opens excel.xls

Staff2 opens excel.xls and cannot edit because Staff1 has locked it.

Staff2 gets the message cannot open excel.xls for writing because 'Administrator' has the file open ('Administrator' is used because the default profile is set when the workstation image is made)

Staff2 whinges to techs because they want to edit.

 

By using this code as a login script it will update staff members username in tools->options->general->User Name (and initials) to their current username. This will give them the error: cannot open excel.xls because 'Staff1' has the file open. Staff2 promptly whinges to Staff1. YAY! Less whinging.

 

The only thing you will have to change is the strOfficePath to your relevant version, Office 2003 is 11.0 which is what I have used.

 

UpdateOfficeUserName.vbs

Set nw = CreateObject("WScript.Network")

Const HKEY_CURRENT_USER = &H80000001

strOfficePath = "Software\Microsoft\Office\11.0\Common\UserInfo"
strMachineName = "."
strUserName = nw.UserName

max = len(strUserName)
For intLoop = 1 to max step 1
   asciiName = asc(mid(strUserName, intLoop, 1))
   if newAsciiName = ""  and newAsciiInitials = "" Then
       newAsciiName = asciiName
       'newAsciiInitials = asciiName
   else
       newAsciiName = newAsciiName & "," & "00" & "," & asciiName
   end if
   If intLoop <= 2 then
       newAsciiInitials = newAsciiName & "," & "00"
   End If
Next
updateName = Split(newAsciiName,",")
updateInitials = Split(newAsciiInitials,",")
strMoniker = "winMgmts:\\" & strMachineName & "\root\default:StdRegProv"
Set oReg = GetObject(strMoniker)
userNameSet = oReg.SetBinaryValue(HKEY_CURRENT_USER, strOfficePath, "UserName", updateName)
userInitialsSet = oReg.SetBinaryValue(HKEY_CURRENT_USER, strOfficePath, "UserInitials", updateInitials)

Posted

Out of interest, what's your setup? Where's it pulling "Administrator" from?

 

Lots of our staff use Excel spreadsheets in the same manner, but the dialog box always tells them the user account of the person who has it open.

Posted

Well,

The Default User profile is made before the workstation is imaged. When you run office for the first time it sets the Username in office as your workstation username.

Last time I did this I removed the user info before I imaged the workstation so that when people logged in it wouldnt have administrator and ask them to confirm their username.

That worked out fine until they noticed a small problem.

If students/staff double clicked a document in mydocs and hadnt already opened word/excel/etc then the software would open but not open the document, leaving them to do it again.

So I reverted back to a pre-set username in the default user profile but now staff whinge when they cant see whos locked files.

 

Pretty sure our contracts should say 'fix all the stupidly small problems that eat up the most time to solve'

Posted
If students/staff double clicked a document in mydocs and hadnt already opened word/excel/etc then the software would open but not open the document, leaving them to do it again.

That is an infuriating bug / 'feature'. Probably confuses countless thousands of people :(

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



×
×
  • Create New...