ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

In search of a partition identifier ...

<< < (2/3) > >>

barney:
When you say 'active' do you mean the partition that is marked as Active that carries the MBR, (I only have one per all drives), or do you mean the current System partition ?
-4wd (February 05, 2011, 05:57 PM)
--- End quote ---

OK, active refers to the partition which supports the OS version I'm using at the moment, i.e., the partition which carries the currently active OS.  Perhaps booted partition would be more clear.

Anyway, curse you, 4wd :P for making me learn another scripting bit - your WhatBoot seems to do what's needful here.  So I'll order the O'Reilly/Safari AutoIt V3:  Your Quick Guide and pray that it really is.  (I hate ebooks.)

Oh, yeah, about that curse ... many, many thanks, as well  :Thmbsup: :Thmbsup:.

4wd:
It that case, perhaps you should sign up for the AutoHK Programming School, (which I'm currently going through in AutoIt) ;)

Here's the source, (a heavily edited version of the CompInfo UDF), but I could have also used AutoIt ScriptOMatic to generate and butcher.

I took the easier route.


--- Code: AutoIt ---#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_UseUpx=n#AutoIt3Wrapper_UseX64=n#AutoIt3Wrapper_Change2CUI=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #region Global Variables and ConstantsIf Not(IsDeclared("$cI_CompName")) Then        Global  $cI_CompName = @ComputerNameEndIfGlobal Const $cI_VersionInfo            = "00.03.08"Global Const $cI_aName                          = 0, _                         $cI_aDesc                              = 4Global  $wbemFlagReturnImmediately      = 0x10, _       ;DO NOT CHANGE$wbemFlagForwardOnly            = 0x20                          ;DO NOT CHANGEGlobal  $ERR_NO_INFO                            = "Array contains no information", _                $ERR_NOT_OBJ                            = "$colItems isnt an object"#endregion Global Variables and Constants #region Boot ConfigurationDim $BootConfig_ComputerGetBootConfig($BootConfig)If @error Then        $error = @error        $extended = @extended        Switch $extended                Case 1                        _ErrorMsg($ERR_NO_INFO)                Case 2                        _ErrorMsg($ERR_NOT_OBJ)        EndSwitchEndIf#endregion Boot Configuration #region ComputerOS ConfigurationDim $OSs_ComputerGetOSs($OSs)If @error Then        $error = @error        $extended = @extended        Switch $extended                Case 1                        _ErrorMsg($ERR_NO_INFO)                Case 2                        _ErrorMsg($ERR_NOT_OBJ)        EndSwitchEndIf#endregion ComputerOS Configuration $CompOS = StringSplit($OSs[1][0],'|')$CompOS[0] = $BootConfig[1][0] If $CmdLine[0] = 1 Then        Switch $CmdLine[1]                Case 'A', 'a'                        ConsoleWrite($CompOS[0])                Case 'O', 'o'                        ConsoleWrite($CompOS[1])                Case 'B', 'b'                        ConsoleWrite($CompOS[3])                Case 'S', 's'                        ConsoleWrite($CompOS[2])                Case 'E', 'e'                        For $i = 0 To 3                                ConsoleWrite($CompOS[$i] & @CRLF)                        Next                Case Else        EndSwitchElse        $info = 'WhatBoot [A|O|B|S|E]' & @CRLF & 'Where: A - Active partition' & @CRLF & '       O - Operating System' & _                                @CRLF & '       B - Boot partition' & @CRLF & '       S - System directory' & @CRLF & '       E - Everything'        ConsoleWrite($info)EndIf Exit Func _ComputerGetBootConfig(ByRef $aBootConfigInfo)        Local $colItems, $objWMIService, $objItem        Dim $aBootConfigInfo[1][8], $i = 1         $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BootConfiguration", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)         If IsObj($colItems) Then                For $objItem In $colItems                        ReDim $aBootConfigInfo[UBound($aBootConfigInfo) + 1][8]                        $aBootConfigInfo[$i][0]  = $objItem.Description                        $i += 1                Next                $aBootConfigInfo[0][0] = UBound($aBootConfigInfo) - 1                If $aBootConfigInfo[0][0] < 1 Then                        SetError(1, 1, 0)                EndIf        Else                SetError(1, 2, 0)        EndIfEndFunc ;_ComputerGetBootConfig Func _ComputerGetOSs(ByRef $aOSInfo)        Local $colItems, $objWMIService, $objItem        Dim $aOSInfo[1][60], $i = 1         $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)         If IsObj($colItems) Then                For $objItem In $colItems                        ReDim $aOSInfo[UBound($aOSInfo) + 1][60]                        $aOSInfo[$i][0]  = $objItem.Name                        $i += 1                Next                $aOSInfo[0][0] = UBound($aOSInfo) - 1                If $aOSInfo[0][0] < 1 Then                        SetError(1, 1, 0)                EndIf        Else                SetError(1, 2, 0)        EndIfEndFunc ;_ComputerGetOSs #region ---- Internal FunctionsFunc _ErrorMsg($message, $time = 0)        ConsoleWrite("Error! - " & $message)EndFunc#endregion Internal Functions
Happy it worked  :D

You might not need the ebook, I find the examples in the help docs and throughout the AutoIt forum are usually enough to get me either headed in the right direction or almost exactly what I require.  The hard part is getting the search terms right.  Many a time I've started writing a function to do something then searched in the forum to find that it's included in a UDF so all I need is a function call  :-[

ATM I can't work out how to tell whether or not the program is run via CLI or GUI which would allow me to add both types of output.  I'm sure it's really easy but stuffed if I can find a variable, (or process), to check for so I can do it.

MilesAhead:
I found this console detection code. I have no idea if it really works though. :)

http://www.autoitscript.com/forum/topic/112127-macro-for-compiled-console/page__p__787423__hl__determine+console+app__fromsearch__1#entry787423

(scroll up to the post by GodlessSinner for the script)

Not exactly great for doing it inside the file you're checking but you can probably work around it somehow. :)

Also there's a new UDF WinApiEx.au3 that has tons of stuff. It's by the guy who figured out how to get the translucent blue glass dialogs on Windows Seven Aero.

4wd:
Great!  Thanks Miles, I'll have a look at it - had a look at the WinApiEx UDF earlier but couldn't see anything.

I couldn't believe they didn't have a macro, (eg. @console), already available.

EDIT: Seems that you need to have UPX'd the compiled script for it to work...bummer!  Still, might be able to adapt it.

Found something here, ie. get the parent process - if it's explorer.exe then it was run via double-click, if it's cmd.exe it's via CLI.

MilesAhead:
Thanks for the link.  Added it to my code snippets. :)

I also found a port of the Linux "file" command:

http://www.vowles-home.demon.co.uk/utils/windows_file_exe.htm

One of the infos output is console or gui when run against an exe file.
C Source is included.  Assuming it works it's some good info on PE fields.
I'm not sure if the exes "compiled" by AutoIt3 conform to the standard.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version