I have a script which make use WMI remote login and takes Global path from IIS of remote server and then will go to that location and then will look for some specific string in web.config . Now the problem here is - If I am running this script for a remote server it gives me Access denied error but once I go to the path manually from my system and after that when I run this script it works perfectly ..
e.g.
I have a server "abc" and location of web.config is" D:\websites\abhi\" then using Wmi I am trying to read this path - \\abc\D$\websites\Abhi\web.config but it throws access denied error . And when I go to start ->Run and go to \\abc\D$\ . and then if I am running this script it works fine after that.
Note- After accessing the path manually it never gives error for that particular server.
Code -
WbemAuthenticationLevelPktPrivacy=6
Set WSHNetwork = CreateObject("WScript.Network" )
astrComputer = frmform1.Optionchooserver.value
'Msgbox"Vmserver: " &astrcomputer
'Set objWMIService = GetObject _
' ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
' & astrComputer & "\root\microsoftiisv2")
strUser="us\svc.cwpcron"
strPassword="MatchB0x"
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
(astrComputer, "\root\microsoftiisv2", strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
Set colItems = objWMIService.ExecQuery _
("Select * from IIsWebVirtualDirSetting")
For Each objItem in colItems
'Msgbox "path for global: " &objitem.path
configParm11=objitem.path&"\web.config"
configParm11=(Mid(ConfigParm11,3,75))
configParm11="\\"&astrcomputer&"\d$"&configParm11
exit for
Next
'Adding WMI second time
'#####
MsgBox "ConfigParm11="&ConfigParm11
'Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService2 = objwbemLocator.ConnectServer _
(astrComputer, "\root\cimv2", strUser, strPassword)
objWMIService2.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
Set colFileList = objWMIService2.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & objitem.path & "'} Where " _
& "ResultClass = CIM_DataFile")
'MsgBox "configParm11"&configParm11
'#######3
For Each objFileItem In colFileList
MsgBox ""
Configparm12=ConfigParm11
'configParm11="\\nvm0543pdv.us.global.schwab.com\D$\WebSites\CWP\Global\v12.1.0-INT08\Public\web.config"
'sgBox "configParm11"&configParm11
Set objFS=CreateObject("Scripting.FileSystemObject")
Set Revconfig=objFS.opentextfile(configparm12,1) '#####Access denied error 'comes for this line"
Revconfig=Revconfig.ReadAll
msgbox "hi"&Revconfig
next