1: set fs = CreateObject("Scripting.FileSystemObject")
2: dim arrStr
3: set objTextFile = fs.OpenTextFile("E:\Virtualpkg\AppvPackageNameResourceId_Advertisment.csv")
4:
5: Do while NOT objTextFile.AtEndOfStream
6: arrStr = split(objTextFile.ReadLine,";")
7: advPackageID = arrStr(1)
8: advCollection = arrStr(5)
9: advName = arrStr(4)
10:
11:
12:
13: strSMSServer = "CMSRV.uza.local"
14: advProgramName = "[Virtual Application]"
15: 'advAssignedSchedule = "16/11/2010 16:25 AM"
16: 'advAssignedScheduleExpire = "12/04/2010 12:59 AM"
17:
18: ' MsgBox "advnaam ="& advname &" en coll="& advCollection &" en packageid=" &advPackageID
19:
20:
21:
22: Set objLoc = CreateObject("WbemScripting.SWbemLocator")
23: Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms")
24: Set Results = objSMS.ExecQuery _
25: ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
26: For each Loc in Results
27: If Loc.ProviderForLocalSite = True Then
28: Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _
29: Loc.SiteCode)
30: strSMSSiteCode = Loc.Sitecode
31: end if
32: Next
33:
34: Set newAdvert = objSMS.Get("SMS_Advertisement").SpawnInstance_()
35: newAdvert.AdvertisementName = advName
36: newAdvert.CollectionID = advCollection
37: newAdvert.PackageID = advPackageID
38: newAdvert.ProgramName = advProgramName
39: 'newAdvert.ExpirationTime = ConvertToWMIDate(advAssignedScheduleExpire)
40: newAdvert.ExpirationTimeEnabled = False
41: 'newAdvert.advertflags = 25
42: newAdvert.PresentTime = ConvertToWMIDate(Now())
43: newAdvert.RemoteClientFlags = &H846
44: newAdvert.Priority = 1
45:
46: path = newAdvert.Put_
47: wscript.echo path
48: Set objAdvert=objSMS.Get(path)
49: strAdvertID = objAdvert.AdvertisementID
50:
51: 'create a non-recurring schedule token
52: Set instToken = objSMS.Get("SMS_ST_NonRecurring").SpawnInstance_()
53: instToken.StartTime = ConvertToWMIDate(advAssignedSchedule)
54: instToken.DayDuration = 0
55: instToken.HourDuration = 0
56: instToken.MinuteDuration = 0
57: instToken.IsGMT = False
58: retval = AddSchedToken(instToken, strAdvertID)
59:
60: Loop
61:
62: objTextFile.Close
63: set objTextFile = Nothing
64: set fs = Nothing
65:
66: Function AddSchedToken(objSchedToken, strAdvertID)
67: 'enlarge the current schedule array by 1
68: Set objAdvert=objSMS.Get _
69: ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'")
70: WScript.Echo(objAdvert.AdvertisementID)
71:
72: Dim newScheduleArray(0)
73: Set newScheduleArray(0) = objSchedToken
74:
75: 'add the new assignment
76: objAdvert.AssignedSchedule = newScheduleArray
77: objadvert.AssignedScheduleEnabled = True
78: AddSchedToken = objAdvert.Put_
79: End Function
80:
81: Function ConvertToWMIDate(strDate)
82: 'Convert from a standard date time to wmi date
83: '4/18/2005 11:30:00 AM = 2005041811300.000000+***
84: strYear = year(strDate):strMonth = month(strDate)
85: strDay = day(strDate):strHour = hour(strDate)
86: strMinute = minute(strDate)
87: 'Pad single digits with leading zero
88: if len(strmonth) = 1 then strMonth = "0" & strMonth
89: if len(strDay) = 1 then strDay = "0" & strDay
90: if len(strHour) = 1 then strHour = "0" & strHour
91: if len(strMinute) = 1 then strMinute = "0" & strMinute
92: ConvertToWMIDate = strYear & strMonth & strDay & strHour _
93: & strMinute & "00.000000+***"
94: end function
95:
96:
97:
98:
99:
100: