Access System Time Remotely using Iron Python





2
Date Submitted Mon. Jul. 6th, 2009 2:02 AM
Revision 1 of 1
Scripter Cloudgen
Tags Iron | Pyton | remote | script | system | Time
Comments 0 comments
Access System Time Remotely using Iron Python. See
reference

import clr, time, sys
sys.stdout.write( "Computer Name or IP:")
computername = sys.stdin.readline().replace("\n","")
sys.stdout.write( "Login name:")
username = sys.stdin.readline().replace("\n","")
sys.stdout.write( "Password:")
password = sys.stdin.readline().replace("\n","")
clr.AddReference("System.Management")
from System.Management import *
connOpts = ConnectionOptions()
connOpts.Username = username
connOpts.Password = password
scope = ManagementScope("\\\\" + computername + "\\root\\cimv2", connOpts)
scope.Connect()
query = ManagementObjectSearcher("Select * from win32_OperatingSystem")
query.Scope = scope
for result in query.Get():
   strTime = time.strptime(result.GetPropertyValue("LocalDateTime")[0:14],"%Y%m%d%H%M%S")
   print time.strftime("%Y/%m/%d %H:%M:%S",strTime)
 

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Scripter Cloudgen
Scripter elsevero

Votes Down