Jump to content
BlueSkyMemory

How to show a hidden partition? - (Moved)

Recommended Posts

Hello guys! I'm a rookie in AutoIt lol.

I've tried to looking up in MSDN and the UDFs, but it can only get the GUID of a usual partition and with the GUID to control it. Now I have no waysūüė•.

Thanks a lot for your help!

Share this post


Link to post
Share on other sites

Moved to the appropriate forum.

Moderation Team


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Posted (edited)

You will need  to add\build in the ms scripting package "WinPE-Scripting.cab" to your winpe to make it work

"WinPE-PowerShell_en-us.cab" and more,  Here are all or more packages that you can add in starting from a clean boot.wim @line 1 using the ADK

Dism /Mount-Image /ImageFile:"C:\WinPE_amd64_PS\media\sources\boot.wim" /Index:1 /MountDir:"C:\WinPE_amd64_PS\mount"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"
Dism /Unmount-Image /MountDir:C:\WinPE_amd64_PS\mount /Commit

Many years ago i have started using this for doin' the disk queries for my winpe boot project

#include <Array.au3>

_GetDriveInfos()

Func _GetDriveInfos()
    $var = DriveGetDrive("FIXED")
    Local $aDiskDrive = 0
    Dim $specifs[$var[0]][8]
    For $i = 1 To $var[0]
        Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
        Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID From Win32_DiskDrive")
        For $DiskDrive In $DiskDrives
            Dim $DiskPartitions = $Services.ExecQuery("Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition")
            For $DiskPartition In $DiskPartitions
                Dim $LogicalDisks = $Services.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
                For $LogicalDisk In $LogicalDisks
                    If $LogicalDisk.DeviceID = $var[$i] Then
                        $specifs[$i - 1][0] = StringUpper($var[$i])
                        $specifs[$i - 1][1] = $DiskDrive.Caption
                        $specifs[$i - 1][2] = Round(DriveSpaceTotal($var[$i]) / 1000)
                        $specifs[$i - 1][3] = Round(DriveSpaceFree($var[$i]) / 1000)
                        $specifs[$i - 1][4] = StringFormat('%.2f', $LogicalDisk.Size / (1024 ^ 3)) & ' GB'
                        $specifs[$i - 1][5] = $DiskPartition.DeviceID
                        $specifs[$i - 1][6] = $LogicalDisk.VolumeName
                        $specifs[$i - 1][7] = $DiskPartition.Type
                    EndIf
                Next
            Next
        Next
    Next
    _ArrayDisplay($specifs, '$specifs')
EndFunc   ;==>_GetDriveInfos

Good luck!

Deye

Edited by Deye

Share this post


Link to post
Share on other sites
12 hours ago, Nine said:

What about diskpart ?

Yes, I can use Diskpart and StringRegExp to make it work. But for compatibility and smaller size, I want to use API instead of other modules.

Share this post


Link to post
Share on other sites
Posted (edited)
11 hours ago, Deye said:

You will need  to add\build in the ms scripting package "WinPE-Scripting.cab" to your winpe to make it work

"WinPE-PowerShell_en-us.cab" and more,  Here are all or more packages that you can add in starting from a clean boot.wim @line 1 using the ADK

Dism /Mount-Image /ImageFile:"C:\WinPE_amd64_PS\media\sources\boot.wim" /Index:1 /MountDir:"C:\WinPE_amd64_PS\mount"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
Dism /Add-Package /Image:"C:\WinPE_amd64_PS\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"
Dism /Unmount-Image /MountDir:C:\WinPE_amd64_PS\mount /Commit

Many years ago i have started using this for doin' the disk queries for my winpe boot project

#include <Array.au3>

_GetDriveInfos()

Func _GetDriveInfos()
    $var = DriveGetDrive("FIXED")
    Local $aDiskDrive = 0
    Dim $specifs[$var[0]][8]
    For $i = 1 To $var[0]
        Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
        Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID From Win32_DiskDrive")
        For $DiskDrive In $DiskDrives
            Dim $DiskPartitions = $Services.ExecQuery("Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition")
            For $DiskPartition In $DiskPartitions
                Dim $LogicalDisks = $Services.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
                For $LogicalDisk In $LogicalDisks
                    If $LogicalDisk.DeviceID = $var[$i] Then
                        $specifs[$i - 1][0] = StringUpper($var[$i])
                        $specifs[$i - 1][1] = $DiskDrive.Caption
                        $specifs[$i - 1][2] = Round(DriveSpaceTotal($var[$i]) / 1000)
                        $specifs[$i - 1][3] = Round(DriveSpaceFree($var[$i]) / 1000)
                        $specifs[$i - 1][4] = StringFormat('%.2f', $LogicalDisk.Size / (1024 ^ 3)) & ' GB'
                        $specifs[$i - 1][5] = $DiskPartition.DeviceID
                        $specifs[$i - 1][6] = $LogicalDisk.VolumeName
                        $specifs[$i - 1][7] = $DiskPartition.Type
                    EndIf
                Next
            Next
        Next
    Next
    _ArrayDisplay($specifs, '$specifs')
EndFunc   ;==>_GetDriveInfos

Good luck!

Deye

Thank you! I've saved it in my disk lol. But it still depends on so many modules. And it cannot detect hidden partitions.

Edited by BlueSkyMemory

Share this post


Link to post
Share on other sites
Posted (edited)
On 4/9/2020 at 2:51 PM, RTFC said:

Maybe try this?

I've found your code is so powerful! By the way, could you please help extract the part that determines whether it is an active partition? Thanks a lot! (To ensure which partitions can be booted)

Edited by BlueSkyMemory

Share this post


Link to post
Share on other sites

Thanks.:) To make a partition bootable (NB: only one (1) partition can be bootable per physical drive, so you always need to edit two flags, not one), look for, and edit boolean IsPrimary (any non-zero value = True; usually 0x01 or 0x80); it's the first byte of each partition table entry in the MBR. In the UDF, see var $partition_active in Func _ReadPartitionEntry for more info.

WARNING: any changes you make to these low-level descriptors is entirely your own responsibility. Please ensure you back up your entire physical drive (not just the files on it), before you start tampering with it. In this particular case, editing a single byte can result in your system no longer booting at all, and no easy way of fixing it. Only proceed if that scenario does not concern you at all.


My Contributions and Wrappers

Share this post


Link to post
Share on other sites
3 hours ago, RTFC said:

Thanks.:) To make a partition bootable (NB: only one (1) partition can be bootable per physical drive, so you always need to edit two flags, not one), look for, and edit boolean IsPrimary (any non-zero value = True; usually 0x01 or 0x80); it's the first byte of each partition table entry in the MBR. In the UDF, see var $partition_active in Func _ReadPartitionEntry for more info.

WARNING: any changes you make to these low-level descriptors is entirely your own responsibility. Please ensure you back up your entire physical drive (not just the files on it), before you start tampering with it. In this particular case, editing a single byte can result in your system no longer booting at all, and no easy way of fixing it. Only proceed if that scenario does not concern you at all.

I've got it! And do you know how to show a hidden partition? I mean, to give a letter to it.

Share this post


Link to post
Share on other sites
Posted (edited)

Assigning drive letters has got nothing to do with physical drives; you need to look into SetVolumeMountpoint for that.

To hide/show logical volumes, see the remarks section of the UDF:

- hide/unhide logical volumes (simply set/reset bit4 of a volume's Partition_Type in its (E)MBR partition entry)

 

Edited by RTFC

My Contributions and Wrappers

Share this post


Link to post
Share on other sites
1 hour ago, RTFC said:

Assigning drive letters has got nothing to do with physical drives; you need to look into SetVolumeMountpoint for that.

To hide/show logical volumes, see the remarks section of the UDF:

- hide/unhide logical volumes (simply set/reset bit4 of a volume's Partition_Type in its (E)MBR partition entry)

 

OK, I've got these APIs. Now I can use FindFirstVolume and FindNextVolume to get all GUIDs, and then assign letter to them. But when I try to use Find First/Next VolumeMountPoint  to find out its letter, I failed (actually it can only get the mountpoint I set to, not the drive letter.)

Share this post


Link to post
Share on other sites

@BlueSkyMemory, The comment I made in your other thread was also meant for you! 

Do NOT quote each and every post you reply to, as that information is already there, so just reply with your answer unless there is a real need to quote something!

Jos  


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

OK. Now the problem is solved. Thanks to everyone! This is my code below, hoping to help others--

Func _GetVolumeMountPoint($sGUID)
    $tPathName = DllStructCreate("char[2048]")
    $aResult = DllCall("Kernel32.dll", 'bool', 'GetVolumePathNamesForVolumeNameA', 'str', $sGUID, 'str', $tPathName, 'dword', DllStructGetSize($tPathName), 'dword', DllStructGetPtr($tPathName))
;~  _ArrayDisplay($aResult)
    Return $aResult[2]
EndFunc

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Atrax27
      I have a webpage that I would like to Focus the Input on a particular field, which is not automatically set as the initial input.
       
      Website:
      https://fiscaloffice.summitoh.net/PropertyTaxValues/PayTaxCC.htm
       
      I want to just simply use the Send(‚Äú154xxx‚ÄĚ) into the ‚ÄúParcel‚ÄĚ field, then Send(‚Äú{ENTER}‚ÄĚ) without cycling through tab presses each time before getting to the correct inputbox, where number of tab press numbers might change depending on a few things (using either IE, chrome, etc). On most websites I try this with, the ‚ÄúLogin ID‚ÄĚ field is the first one that the cursor jumps to so all I do is just start a Send command, but here I can‚Äôt do that since it‚Äôs not the initial cursor location.
       
      I‚Äôve read a few things on the forums about ‚Äú_WinAPI_SetFocus‚ÄĚ but that appears to work on AutoIT generated form fields only (see below code), I don‚Äôt know how to translate it for website use, thanks for any help!
       
      #include <GUIConstantsEx.au3> #Include <WinAPI.au3>   $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("", 10, 10, 400, 20) GUICtrlCreateButton("Test", 10, 100, 80, 30) GUICtrlSetState(-1, $GUI_FOCUS)   GUISetState() Sleep(5000) _WinAPI_SetFocus(ControlGetHandle("Test", "", $hInput)) While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd  
         
    • By paradox109
      Hello, 
      I have A simple question about http request. What would be the fastest way to send mupltiple http request at the same time with autoit? The only way i figured  out was to to start multiple processes. This way works fine but its not really a good way. What user would like to see 15 processes running in the background at the same time. I know multithread is also not available in autoit.
    • By UEZ
      Here another approach to check if a script was already started using atoms and semaphores.
       
      Atom:
      #include <MsgBoxConstants.au3> Global $iSingleton = Singleton() If Not $iSingleton Then Exit MsgBox($MB_TOPMOST, "Singleton Test", "Process is already running!") EndIf MsgBox($MB_TOPMOST, "Singleton Test", "Singleton atom initialized: " & $iSingleton) Singleton_Delete($iSingleton) ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton ; Description ...: Checks if the script has been started already. ; Syntax ........: Singleton([$sOccurrenceName = @ScriptFullPath]) ; Parameters ....: $sOccurrenceName - [optional] a string value. Default is @ScriptFullPath. ; Return values .: If the function succeeds, the return value is the newly created atom or 0 else error is set and false is returned. ; Author ........: UEZ ; Modified ......: ; Remarks .......: If Singleton finds the atom it will return 0 and the atom token will be set to extended macro. It can be used to get the atom string using _WinAPI_AtomGlobalGetName. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalfindatomw ; https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globaladdatomw ; Example .......: No ; =============================================================================================================================== Func Singleton($sOccurrenceName = @ScriptFullPath) Local $iFind = _WinAPI_AtomGlobalFind($sOccurrenceName) If @error Then Return SetError(1, 0, False) If $iFind Then Return SetExtended($iFind, 0) Local $iAtom = _WinAPI_AtomGlobalAdd($sOccurrenceName) If @error Then Return SetError(2, 0, False) Return $iAtom EndFunc ;==>Singleton ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton_Delete ; Description ...: Deletes the atom generated by the first started script. ; Syntax ........: Singleton_Delete($iAtom) ; Parameters ....: $iAtom - an integer value which was generated by Singleton ; Return values .: True if successful else false. ; Author ........: UEZ ; Modified ......: ; Remarks .......: Don't forget to call Singleton_Delete before first started script ends. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globaldeleteatom ; Example .......: No ; =============================================================================================================================== Func Singleton_Delete($iAtom) _WinAPI_AtomGlobalDelete($iAtom) If @error Then Return SetError(1, 0, False) Return True EndFunc ;==>Singleton_Delete ;internal functions Func _WinAPI_AtomGlobalFind($sAtomString) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalFindAtomW", "wstr", $sAtomString) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] EndFunc ;==>_WinAPI_AtomGlobalFind Func _WinAPI_AtomGlobalAdd($sAtomString) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalAddAtomW", "wstr", $sAtomString) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] EndFunc ;==>_WinAPI_AtomGlobalAdd Func _WinAPI_AtomGlobalDelete($nAtom) Local $aReturn = DllCall("kernel32.dll", "short", "GlobalDeleteAtom", "short", $nAtom) If @error Then Return SetError(1, 0, -1) Return $aReturn[0] = 0 EndFunc ;==>_WinAPI_AtomGlobalDelete Func _WinAPI_AtomGlobalGetName($nAtom, $iBufferSize = 512) Local $tBufferAtom = DllStructCreate("wchar name[" & $iBufferSize & "]") Local $aReturn = DllCall("kernel32.dll", "uint", "GlobalGetAtomNameW", "short", $nAtom, "struct*", $tBufferAtom, "int", $iBufferSize) If @error Or Not $aReturn[0] Then Return SetError(1, 0, -1) Return $tBufferAtom.name EndFunc ;==>_WinAPI_AtomGlobalGetName  
      Semaphore:
      #include <MsgBoxConstants.au3> #include <WinAPIError.au3> Global $iSingleton = Singleton("&]8h/x87</htFV4-K*&.b.w~") If Not $iSingleton Then Exit MsgBox($MB_TOPMOST, "Singleton Test", "Process is already running!") EndIf MsgBox($MB_TOPMOST, "Singleton Test", "Singleton Semaphore initialized: " & $iSingleton) ; #FUNCTION# ==================================================================================================================== ; Name ..........: Singleton ; Description ...: Checks if the script has been started already. ; Syntax ........: Singleton($sOccurrenceName) ; Parameters ....: $sOccurrenceName - a string value which will be used to create the semaphore handle. ; Return values .: True if Singleton started the first time. False if script was already started ; Author ........: UEZ ; Modified ......: ; Remarks .......: The system closes the handle automatically when the process terminates. The semaphore object is destroyed when its last handle has been closed. ; Related .......: ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsemaphorea ; Example .......: No ; =============================================================================================================================== Func Singleton($sOccurrenceName) If StringLen($sOccurrenceName) > 260 Then $sOccurrenceName = StringLeft($sOccurrenceName, 260) Local $aReturn = DllCall("kernel32.dll", "handle", "CreateSemaphoreA", "ptr", Null, "long", 0, "long", 1, "str", $sOccurrenceName) If @error Or Not $aReturn[0] Then Return SetError(1, 0, -1) Return SetExtended($aReturn[0], $aReturn[0] And _WinAPI_GetLastErrorMessage() = "The operation completed successfully.") EndFunc ;==>Singleton  
      Just start the script twice to see if it works.
      The disadvantage of using atoms is that atoms have a memory that means when your app is crashing or you forgot to delete the atom then the atom does still have the $sOccurrenceName saved and thus Singleton will not work if you use the same same value for $sOccurrenceName.
      With semaphore you don't have this issue.
       
      Thanks to jj2007 and SARG.
    • By nacerbaaziz
      good morning autoit team
      please i need your help
      am trying to make an program that work with hotkeys
      it function is to change the volume to the current application
      e.g when i select the vlc window by using this hotkey i will be able to change the vlc volume with out changing the system volume.
       am able to get the process handle and the process name of the window
      but when am trying to get or set the volume i does not succeded
      i tried to search in this forums but no result.
      can you please guide me to do that.
      am waiting for your answers
      thanks in advanced
    • By undcover
      Hello, I'm automating part of the note taking ability of my old bad POS, I managed to do much of the heavy lifting in the past weeks, I can finally do everything i want and more.
      Now I have a form with two buttons that expand the form to show a note taking beast that can lets us escape the hell of the one way editing the POS actually support (no cursor just delete. want to change the time on that order better delete everything and start the note from scratch, well not anymore)
      Now i'm stuck, my form shows up as two buttons over the POS window, however I need it to go away when I minimized the POS or switch to a different page or application, I was able to do so by doing a while loop, it worked badly as it will repeat the show command infinitely and if i break the loop then there's no way to restart the loop if the user didn't interact with the buttons directly.
      I have many ways I could know when controls are visible and it worked, I just don't have a way of constantly checking for this without straining the CPU, I know if I work it somehow I could do a while loop that can work, but it'll be CPU intensive. (Bad POS entails BAD PC)
      Should I make another form that does the loop? can I make the loop slower ?
      I'm using  VB.net VS 2017 with AutoitX dll.
      EDIT: Hello anyone who searched for this, if you're and idiot like me and forgot that Timers exist then this will jog your memory
       
      Add a timer to your form, set the timer for 1 sec intervals (dealers choice)
      start your timer (within form load or manually)
      Timer1.start()
      then double click the timer to create a Timer tick (for my case the control visibility test i want to make each second)
      it should look something like this :
          Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick         dim visibleform = ait.ControlCommand("my app", "", "[NAME:wacontact]", "IsVisible", "")         If visibleform = 0 Then             Me.Hide() ElseIf visibleform = 1 And Me.Visible = False Then ' to prevent the timer ticks from interupting any sendkeys or something we put two conditions. Me.Show() End If     End Sub remarks: ait. is the call I set for Autoit DLL.
       
       
       
×
×
  • Create New...