Page 1 of 1 1
Topic Options
#199927 - 2010-09-16 09:52 PM SMS Com Automation
sliver16 Offline
Fresh Scripter

Registered: 2007-12-10
Posts: 10
hey all,

having some trouble with a COM script that I am converting from VBS to Kix. We are using COM to grab available SMS packages from their client machines and then install them in a certain order. I am currently trying to install 1 package as a test but the ExecuteProgram command keeps failing with a syntax error. I have tried every possible syntax I can think of. Can anyone help???

Kix Code:
 Code:
Dim $oUIResource 
Dim $oPrograms 
Dim $oProgram 

$oUIResource = CreateObject("UIResource.UIResourceMgr")

;check if resource was created
If $oUIResource = ""
	MessageBox("Could not create Resource Object Quitting", "No Resource Object", 16)
	Quit
EndIf

;Check for mandatory pending package
If $oUIResourceMgr.IsMandatoryProgramPending = 1 
	$null = MessageBox("Mandatory program pending. Try again later.", "Mandatory Program Pending", 16)
	$oUIResource = Nothing
	Quit
EndIf



;Get List of Available apps
$oPrograms = $oUIResource.GetAvailableApplications

;Check if Available apps is created
If $oPrograms = ""
	MessageBox("Failed to get programs object - quitting", "No Programs Object", 16)
   $oUIResource = ""
EndIf 

;Display number of programs
$numprog = $oPrograms.Count
MessageBox("$numprog", "Success...Program Amount", 16)



;Show all Programs and program names
For Each $oProgram in $oPrograms
	$fullnameprog = $oProgram.FullName
	$packidprog = $oProgram.PackageId
	$null=MessageBox("$fullnameprog", "Full Name of Package", 16)
	$null=MessageBox("$packidprog", "Package ID", 16)
		
	If $oProgram = ""
		$null = MessageBox("Couldn't get the program", "Fail", 16)
		$oUIResource = ""
		Quit
	Else
		If $packidprog = "CEN0172C"
		   $null = MessageBox("$fullnameprog", "Running Program", 16)
			$test = $oUIResource.ExecuteProgram ($fullnameprog,$packidprog)
			$null = MessageBox("$test", "Result", 16)
		Else
			$null = MessageBox("$packidprog", "Different Package ID", 16)
		EndIf		 
		$oProgram = ""
		$oUIResource = ""
	EndIf
	
Next 
		
$oProgram = ""
$oUIResource = ""
Quit


Sample VBS Code
 Code:
if oUIResourceMgr.IsMandatoryProgramPending = 1 Then
        Wscript.Echo "Mandatory program pending. Try again later."
        Set oUIResource=Nothing
        Exit Sub
    End If

    Set oProgram = oUIResource.GetProgram(programId,packageId)
    if oProgram is Nothing Then
        WScript.Echo "Couldn't get the program"
        Set oUIResource=Nothing
        Exit Sub
    End If
    
    Wscript.Echo "Running program: " & oProgram.FullName
    oUIResource.ExecuteProgram programId, packageID 
 
    Set oProgram=Nothing
    Set oUIResource=Nothing

Associated COM articles from Microsoft:

http://msdn.microsoft.com/en-us/library/cc143667.aspx
http://msdn.microsoft.com/en-us/library/cc143231.aspx


It fails at this line every time with a syntax error:

$test = $oUIResource.ExecuteProgram ($fullnameprog,$packidprog)


Thanks again, any help is appreciated!!


Edited by Allen (2010-09-16 10:19 PM)
Edit Reason: added code tags

Top
#199928 - 2010-09-16 09:56 PM Re: SMS Com Automation [Re: sliver16]
sliver16 Offline
Fresh Scripter

Registered: 2007-12-10
Posts: 10
Please note the program ID has spaces and dashes in it...I tried running it as so:

$test = $oUIResource.ExecuteProgram ("$fullnameprog", "$packidprog")

But still no luck....


Edited by sliver16 (2010-09-16 10:07 PM)

Top
#199931 - 2010-09-16 10:42 PM Re: SMS Com Automation [Re: sliver16]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
At the line where the ExecuteProgram is comment the line so it doesn't run, and place the following lines right above it...

 Code:
? "Fullnameprg:  " + $fullnameprog
? " packidprog:  " + $packidprog
;$test = $oUIResource.ExecuteProgram ($fullnameprog,$packidprog)


Do these values look right? If not, its possible the error is higher in the script.

Top
#199940 - 2010-09-17 02:22 PM Re: SMS Com Automation [Re: Allen]
sliver16 Offline
Fresh Scripter

Registered: 2007-12-10
Posts: 10
Allen...yes they both look correct. I think the issue is that the $FullNameProg name has spaces in it. The error I get is:

Expected ')'!

So Im guessing it has to be a syntax thing?? So how would the syntax work for a COM object if

$Fullnameprog - has spaces in it
$packidprog - Will never have spaces

$test = $oUIResource.ExecuteProgram ($fullnameprog,$packidprog)

Top
#199941 - 2010-09-17 03:06 PM Re: SMS Com Automation [Re: sliver16]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Maybe?
 Code:
$test = $oUIResource.ExecuteProgram ('"' + $fullnameprog + '"',$packidprog)

Top
#199980 - 2010-09-20 09:49 PM Re: SMS Com Automation [Re: Allen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
As Richard pointed out earlier:
 Code:
$test = $oUIResource.ExecuteProgram ($fullnameprog, $packidprog, Not 0)


Although your first MS link points out in C# code that it should be "0" instead of "Not 0". But try both, I'd prefer to use just 0.


Edited by apronk (2010-09-20 09:53 PM)
Edit Reason: Added stuff

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 739 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.057 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org