Sign in to follow this  
Followers 0
wardy

Quering Services

5 posts in this topic

Hi all, just getting into Autoit and so far really like it but have gotten well stuck on this.

Trying to query some remote services using SC. Works a treat if the service name has no spaces in it. But, if the service name has a space it throws an error.

Any sugestions or points would be most welcome!

This works a treat

$service = "Messenger"

Run(@ComSpec & " /c " & "sc \\" & "Exchange1 " & "query " & $service & " >>C:\Scripts\AVCheck\test.txt", "", @SW_HIDE)

This doesn't!

$service = "McAfee GroupShield"

Run(@ComSpec & " /c " & "sc \\" & "Exchange1 " & "query " & $service & " >>C:\Scripts\AVCheck\test.txt", "", @SW_HIDE)

Share this post


Link to post
Share on other sites



This works a treat

$service = "Messenger"

Run(@ComSpec & " /c " & "sc \\" & "Exchange1 " & "query " & $service & " >>C:\Scripts\AVCheck\test.txt", "", @SW_HIDE)

This doesn't!

$service = "McAfee GroupShield"

Run(@ComSpec & " /c " & "sc \\" & "Exchange1 " & "query " & $service & " >>C:\Scripts\AVCheck\test.txt", "", @SW_HIDE)

Hi, and welcome to a great community of users.

Commands, filenames, and/or options with spaces in them must be enclosed in quotes when used on the command line. So, you can do this:

$service = "McAfee GroupShield"
$service = CHR(34) & $service & CHR(34) ; chr(34) is ascii code for " quotation mark
Run(@ComSpec & " /c " & "sc \\" & "Exchange1 " & "query " & $service & " >>C:\Scripts\AVCheck\test.txt", "", @SW_HIDE)oÝ÷ Úò¢çéyÛayÈkßý²)ò¢êÜ¢iÙb殶­sbb33c·6W'f6RÒgV÷C´Ö4fVRw&÷W6VÆBgV÷C°¥'6öÕ7V2fײgV÷C²ö2gV÷C²fײgV÷C·62b3#²b3#²gV÷C²fײgV÷C´W6ævSgV÷C²fײgV÷C·VW'gV÷C²fײ4"3Bfײb33c·6W'f6Rfײ4"3BfײgV÷C²fwC²fwC´3¢b3#µ67&G2b3#´d6V6²b3#·FW7BçGBgV÷C²ÂgV÷C²gV÷C²Â5uôDRoÝ÷ Úò¢çëiÊ&n)Ú¶*'¡û"   ^jw]¢æåz«¨µë"*.­Ê&©Ý)Þ­êeiDz¢êÞÆ+-x¢æåz«¨µë0Ølx%zƧvëv뮧w*.®Ç«¾'©)¶¬jëh×6$service = "McAfee GroupShield"
Run(@ComSpec & ' /c ' & 'sc \\' & 'Exchange1 ' & 'query "' & $service & '" >>C:\Scripts\AVCheck\test.txt', "", @SW_HIDE)oÝ÷ Øky©eÉשzwl¢|!jÝý±æ¬ë-~ò¢ëh~e£)z»(©eÊÞ}êèê¶øÁ¬¬jÈ­ßÛ,¢g­g¬ªÝ¶zkiÉ(~ȧW×h¹¹^ªê-zÌ!z{a{-ý­êâ[zÈyæaz°%²7öiè¶Ë«{rÊ·ö·­æ¤x.§*.­Ê&©Ý)Þmëpyéíꮢßܪê-¶ªºlr«¨¶Ø^±êïz¹Úæ§vØ^ªç«ÉÊ&©ÝJ)©êåG­+ºÚ"µÍÌÍÜÙXÙHH    ][ÝÓXÐYYHÜÝÚY[    ][ÝÂ[ÛÛTÜXÈ   [È ][ÝÈØÈØÈ  ÌLÉÌLÑ^Ú[ÙLH]YH   ][ÝÈ  [ÈÒÍ
H   [È ÌÍÜÙXÙH    [ÈÒÍ
H   [È ][ÝÈ  ÝÉÝÐÎÌLÔØÜÉÌLÐUÚXÚÉÌLÝÝ   ][ÝË  ][ÝÉ][ÝËÕ×ÒQJ

Hope that helps

Share this post


Link to post
Share on other sites

It certainly does help! Thank you for your time and on being so clear,

ASCII codes huh.. I'll get reading... :))

Ward

Share this post


Link to post
Share on other sites

Welcome to the forum.

You don't need ComSpec to run sc.exe and you don't have to write the output of sc.exe to a file. AutoIt can "read" the output of sc.exe via the STDIO functions. Here is a small sample of how that can be done:

$service = "messenger"
$PID = Run("sc query " & $service, "", "", 3)

While 1
    $line = StdoutRead($PID)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)

    $var1 = StringInStr($line, "STATE   ")
    $var2 = StringMid($line, $var1, 22)
    $var3 = StringRight($var2, 1)
    MsgBox(0, "", ">>>" & $var3 & "<<<")
WEnd

...but AutoIt can also interface directly with Dynamic Link Libraries (DLLs) so you might want to look at this thread: http://www.autoitscript.com/forum/index.ph...;showtopic=6487

...enjoy AutoIt...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Wow, AutoIT gets even better! Thanks to all who've helped with this, going to have a play and incorporate this into my work.

Cheers!

Wardy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0