iamuser
asked on
VB Script and getting domain username
I have an ini file that I'm using. In it are 2 lines, a SMB link to an application and a hostname identifier.
This is what the app.ini file looks like:
FilePath=\\server\applicat ion.exe
Hostname = Computer
I want to use a VB script to take the username of the person who’s logged in and replace ‘computer’ with that user’s domain username. This way I don't have to edit every single app.ini
This is my script, when I double click it, it runs fine but it doesn’t replace the hostname with my username
' --- Global Declarations ---
Dim oWshShell
Dim ofso
Dim file
Dim sStartupCommand
Dim oWshNetwork
dim sLoginName
Dim sUserIniLocation
Dim sUserIniFile
Dim sBaseIniFile
Dim sHostname
Dim oParmFile
dim strParmFileText
dim sReplaceText
'
Set ofso = CreateObject("Scripting.Fi leSystemOb ject")
Set oWshShell = CreateObject("Wscript.Shel l")
Set oWshNetwork = CreateObject("Wscript.Netw ork")
SHostname = Environ("Username")
sUserIniLocation = "C:\localfolder\txt\"
sUserIniFile = sUserIniLocation & "app.ini"
sReplaceText = "Hostname=computer"
set oParmFile = oFSO.openTextFile(sUserIni File)
strParmFileText = oParmFile.readall
oParmFile.close
strParmFileText = replace(strParmFileText, sReplaceText, SHostname)
set oParmFile = oFSO.openTextFile(sUserIni File,2)
oParmFile.write(strParmFil eText)
oParmFile.close
This is what the app.ini file looks like:
FilePath=\\server\applicat
Hostname = Computer
I want to use a VB script to take the username of the person who’s logged in and replace ‘computer’ with that user’s domain username. This way I don't have to edit every single app.ini
This is my script, when I double click it, it runs fine but it doesn’t replace the hostname with my username
' --- Global Declarations ---
Dim oWshShell
Dim ofso
Dim file
Dim sStartupCommand
Dim oWshNetwork
dim sLoginName
Dim sUserIniLocation
Dim sUserIniFile
Dim sBaseIniFile
Dim sHostname
Dim oParmFile
dim strParmFileText
dim sReplaceText
'
Set ofso = CreateObject("Scripting.Fi
Set oWshShell = CreateObject("Wscript.Shel
Set oWshNetwork = CreateObject("Wscript.Netw
SHostname = Environ("Username")
sUserIniLocation = "C:\localfolder\txt\"
sUserIniFile = sUserIniLocation & "app.ini"
sReplaceText = "Hostname=computer"
set oParmFile = oFSO.openTextFile(sUserIni
strParmFileText = oParmFile.readall
oParmFile.close
strParmFileText = replace(strParmFileText, sReplaceText, SHostname)
set oParmFile = oFSO.openTextFile(sUserIni
oParmFile.write(strParmFil
oParmFile.close
ASKER
I will give that a try
ASKER
it worked but it replaced the entire "hostname=computer" line with a "CN, DC" line
I like to replace only the 'computer' portion of that line
I like to replace only the 'computer' portion of that line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Let me try that, thanks for the help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will re-post again since this is so old
Open in new window
withOpen in new window