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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote access to file attributes

Status
Not open for further replies.

RoMa68

Technical User
Feb 7, 2006
27
DE
Running the following script I get the error : "file not found"!

the placehoulders contain:
strServer3: "RM2MS000651"
StackerLog: "\C$\PMX\_log\_STACKERGW\PDLog-admin_mes.log"

the login within ConnectServer is local admin!

If I map a network connection to this server, everything works fine!

Set objSWbemServices3 = objSWbemLocator.ConnectServer (strServer3, "root\cimv2", strUser3, strPword3, "MS_409", "ntlmdomain:" + strDomain3)
Set colSwbemObjectSet3 = objSWbemServices3.ExecQuery("Select * From Win32_Process",,48)

WScript.Echo "FSO.GetFile(\\"& strServer3 & StackerLog &")"
Set StackerLogFile = FSO.GetFile("\\" & strServer3 & StackerLog)
StackerLogFileDLM = StackerLogFile.DateLastModified

thanks for your hepl

MR
 
you are connecting to the WMI service on the remote machine using alternative creditials,,,,these creditials do not apply to an FSO manipulation. you have access to the box via WMI, i would suggest using this WMI DCOM connection to grab your file details,,,have a look at the Win32_File class...i think
 
somethign like

Set colSwbemObjectSet3 = objSWbemServices3.ExecQuery("Select * From CIMData_File Where Name = 'c:\PMX\_log\_STACKERGW\PDLog-admin_mes.log'",,48)
 
CIMData_File looks like the class you will be interested in
 
...seems to - but it does not work!

Error '0x80041017', Source (null)?

I don't know - where the problem is.


Set objSWbemServices3 = objSWbemLocator.ConnectServer(strServer3, "root\cimv2", strUser3, strPword3, "MS_409", "ntlmdomain:" + strDomain3)
Set colSwbemObjectSet3 = objSWbemServices3.ExecQuery("Select * From Win32_Process",,48)

WScript.Echo "Select * From CIMData_File Where Name = '" & StackerLog & "'"
Set colSwbomFileSet3 = objSWbemServices3.ExecQuery("Select * From CIMData_File Where Name = '" & StackerLog & "'",,48)

'causes error 'object needed colSwbenCIMData_File3', 800a01a8, runtime error
WScript.Echo "DLM" & colSwbemCIMData_File3.LastModified

'causes error named above
For Each CIMData_File3Set in colSwbomFileSet3
StackerLogFileDLM = colSwbomFileSet3.LastModified
Next
 
what is your StackerLog string = to?
it needs to be "c:\...\filename"

do you get anything back from your Processes collection??
 
>[tt]CIMData_File[/tt]
[tt]CIM_DataFile[/tt]
 
@mrmovie:
what do you mean? the path is correct...

@tsuji:
thanks but same error?!
 
RoMa68.

you said

StackerLog: "\C$\PMX\_log\_STACKERGW\PDLog-admin_mes.log"

then you call

objSWbemServices3.ExecQuery("Select * From CIMData_File Where Name = '" & StackerLog & "'",,48)

therefore unless something has changed with StackerLog it will fall on its face due to you needing "c:\PMX\_log\...log" as you are now using DCOM to access the WMI instance on the actual target machine
 
...ok - but I changed it to:

"C:\PMX\_log\_STACKERGW\PDLog-admin_mes.log"

I even tried "C:boot.ini" which is a windows-file but with the same result :eek:(
 
The result of this query will be an array/group?

So I have to get this 'single' dataset with a:
For Each X in Y
...
Next
 
yeap, thats right,
go back to your processes query, can you return a collection of Win32_Process's? once you have got that working (which should be easier) once this is working you can confirm you have good connection etc etc
 
Hi,

this part...
---------------
Set objSWbemServices3 = objSWbemLocator.ConnectServer(strServer3, "root\cimv2", strUser3, strPword3, "MS_409", "ntlmdomain:" + strDomain3)
Set colSwbemObjectSet3 = objSWbemServices3.ExecQuery("Select * From Win32_Process",,48)
---------------
...is working well - I' fetching the following data:
---------------
For Each objProcess in colSwbemObjectSet3
'timestamp for starting this machine
If objProcess.Name = Process2 Then
Server3Stat = " (runnig since: " & FormatCreationTime(objProcess.CreationDate)
Server3Stat = "<font color=#"&Black&">" & Server3Stat & "</font>"
End If

For counter = 0 to ubound(ProcessList)
If Debug = 1 Then WScript.Echo "checking for Process: " & ProcessList(counter)
'WScript.Echo "ubound(ProcessList): " & ubound(ProcessList) & VbCrLf & "ProcessList(" & counter & "): " & ProcessList(counter) & VbCrLf & "objProcess.Name: " & objProcess.Name
If ProcessList(counter) = objProcess.Name Then
If Debug = 1 Then WScript.Echo "found pair:" & ProcessList(counter) & "/" & objProcess.Name
'WScript.Echo "found pair:" & ProcessList(counter) & "/" & objProcess.Name & VbCrLf & "counter: " & counter
ProcessRunningSince = " (runnig since: " & FormatCreationTime(objProcess.CreationDate)
ProcessRunningSince = "<font color=#"&Black&">" & ProcessRunningSince & "</font>"
ProcessStatusList(counter) = " <p class=MsoPlainText style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:0cm'><span class=GramE><b style='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:10.0pt;font-family:&quotLucida Console&quot;mso-ansi-language:EN-US'>" & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=#"&Blue&">" & PNameList(counter) & "</font><font color=#"&LimeGreen&"> is activ.</font> </b>"&ProcessRunningSince&"</font></span></span></span><o:p></o:p></p>"
End If
Next
Next
'For Each CIM_DataFile3Set in colSwbomFileSet3
' StackerLogFileDLM = CIM_DataFile3Set.LastModified
'Next
---------------
...the commented part does not work (see error message in last postings)...
 
>@tsuji: thanks but same error?!
The same error or not the same error does not mean anything. The change I propose is not really negotiable. It is just a typo of mrmovie's part and it's an error on your part because you don't change it.
 
try and get the DataFile WMI query working on your local machine, then transfer this to the remote box. have a look at some examples on retrieving DataFile collections in WMI and try and get your moniker string syntax correct
 
Hi guys,

somewhere in the web I found this one:
---------------------------------------
Function GetFileSize(strSrv,strFile,UserName,Password)
On Error Resume Next

strFile=Replace(strFile,"\","\\") 'filepath must use \\ instead of \

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
SWBemlocator.Security_.AuthenticationLevel=WbemAuthenticationLevelPktPrivacy
Set objWMIService = SWBemlocator.ConnectServer(strSrv,"\root\cimV2",UserName,Password)
If Err.Number<>0 Then
strData="Error connecting to " & strSrv & ". Error #" & Hex(err.Number) &_
" " & Err.Description
GetFileSize=strData
Err.Clear
Else
strQuery="Select name,filesize from CIM_DATAFILE where name='" & strFile & "'"
Set colItems = objWMIService.ExecQuery(strQuery,,48)
For Each file In colItems
strResults=file.filesize
Next
GetFileSize=strResults

End If

End Function
---------------------------------------
now my function is working, I just replaced the '\' with '\\' within the filepath!

This means my path looks like this: "C:\\PMX\\_log\\_STACKERGW\\PDLog-admin_mes.log"

Thanks for your support!

MR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top