kaushal01981
asked on
VB Script to add site to Java Exception List
I am trying to write a script to add sites to Java exception list. So I need to append Exception.Sites file which exists at location C\Users\UserName]\AppData\ LocalLow\S un\Java\De ployment\S ecurity
Below is the script
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Open_as_Unicode = -1
Set objNetwork = CreateObject("WScript.Netw ork")
Set objShell = CreateObject( "WScript.Shell" )
strFolder = "C:\Users\" & objNetwork.UserName & "\AppData\LocalLow\Sun\Jav a\Deployme nt\securit y"
strFile = "exception.sites"
strPath = strFolder & "\" & strFile
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
Set dctURLs = CreateObject("Scripting.Di ctionary")
dctURLs.CompareMode = vbTextCompare
dctURLs.Add "http://uslxswp6:8278", 0
If (FSO.FileExists(strPath) = True) Then
Set objFile = FSO.OpenTextFile(strPath, ForReading, 0)
' Read through the current list to maintain any user added URLs
While Not objFile.AtEndOfStream
strURL = Trim(objFile.ReadLine)
If strURL <> "" Then
If dctURLs.Exists(strURL) = False Then dctURLs.Add strURL, 0
End If
Wend
objFile.Close
Set objFile = Nothing
End If
msgbox strpath
Set objFile = FSO.CreateTextFile(strPath , True, 0)
For Each strURL In dctURLs
I am running the script in system context.
Problem is that strfolder (line 7) is not resolving to user name who is logged in.
It is resolving to something else. Please help.
Below is the script
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Open_as_Unicode = -1
Set objNetwork = CreateObject("WScript.Netw
Set objShell = CreateObject( "WScript.Shell" )
strFolder = "C:\Users\" & objNetwork.UserName & "\AppData\LocalLow\Sun\Jav
strFile = "exception.sites"
strPath = strFolder & "\" & strFile
Set FSO = CreateObject("Scripting.Fi
Set dctURLs = CreateObject("Scripting.Di
dctURLs.CompareMode = vbTextCompare
dctURLs.Add "http://uslxswp6:8278", 0
If (FSO.FileExists(strPath) = True) Then
Set objFile = FSO.OpenTextFile(strPath, ForReading, 0)
' Read through the current list to maintain any user added URLs
While Not objFile.AtEndOfStream
strURL = Trim(objFile.ReadLine)
If strURL <> "" Then
If dctURLs.Exists(strURL) = False Then dctURLs.Add strURL, 0
End If
Wend
objFile.Close
Set objFile = Nothing
End If
msgbox strpath
Set objFile = FSO.CreateTextFile(strPath
For Each strURL In dctURLs
I am running the script in system context.
Problem is that strfolder (line 7) is not resolving to user name who is logged in.
It is resolving to something else. Please help.
ASKER
yes, but the problem is that I have to write operation on a file residing in AppData folder. Users do not have permission to that folder, so have to run the script in SCCM through System context so that my script is able to write to AppData location.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Explanation made my issue to resolve.
You either have to program some logic that you can detect the user you need (ex. enumerate c:\users\ folder or query WMI), or just have it run as the user currently logged in.