Jump to content

psikoh

Members
  • Posts

    8
  • Joined

  • Last visited

psikoh's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. This is a great idea Unfortunately, it doesn't work for me I'm using Vista, not sure about XP. When i open up the config screen it says no folders defined, so i create a new one, the list is then blank (no folders to select either), I add a new file (via menu), again the list and folders are still blank. I close the config screen, refresh my icons and the folder is in the portable apps menu, but when i click on it I get this error Line -1: Error: Array variable subscript badly formatted. And then nothing happens. Using the version posted today as I only just found this
  2. Hey, I'm trying to retrieve a connecting sessions ip address in terminal services for use in other scripts. I found two threads on this but neither of them have autoit code that works, only vb code (not vbs), and I'm having trouble converting this. This is also my first attempt at using DllCall.. Here is the original vb code CODE4. Clay Keller Aug 11 2004, 8:53 pm show options Newsgroups: microsoft.public.windows.terminal_services From: "Clay Keller" <NO_claySPAM_kel...@hotmail.com> - Find messages by this author Date: Wed, 11 Aug 2004 20:53:03 -0500 Local: Wed, Aug 11 2004 8:53 pm Subject: Re: Need to capture client IP address Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse Here is a little VB module that is a subset of functionality from a larger Terminal services module I wrote. This will do what you want. Attribute VB_Name = "RDPGetMachine" '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'This Code Snippet taken from mdlTSAPI.bas written by Clay Keller '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Option Explicit 'Terminal Services API Declarations Private Declare Function WTSQuerySessionInformation Lib "wtsapi32.dll" _ Alias "WTSQuerySessionInformationA" _ (ByVal hServer As Long, _ ByVal SessionID As Long, _ ByVal WTSInfoClass As Long, _ ByRef ppBuffer As Long, _ ByRef pBytesReturned As Long _ ) As Long Private Declare Sub WTSFreeMemory Lib "wtsapi32.dll" _ (ByVal pMemory As Any) 'Win32 Declarations Private Declare Sub CopyMemory Lib "kernel32.dll" _ Alias "RtlMoveMemory" _ (ByRef aDestination As Any, _ ByVal lSource As Any, _ ByVal lBytesToCopy As Long _ ) 'Terminal Services Constants and Definitions Public Enum WTS_INFO_CLASS WTSInitialProgram WTSApplicationName WTSWorkingDirectory WTSOEMId WTSSessionId WTSUserName WTSWinStationName WTSDomainName WTSConnectState WTSClientBuildNumber WTSClientName WTSClientDirectory WTSClientProductId WTSClientHardwareId WtsClientAddress WTSClientDisplay WTSClientProtocolType End Enum Public Type WTS_CLIENT_ADDRESS AddressFamily As Long 'DWORD This member can be AF_INET, AF_IPX, AF_NETBIOS, or AF_UNSPEC Address(20) As Byte ' BYTE Address[20] End Type Private Const WTS_CURRENT_SERVER_HANDLE = 0& Private Const WTS_CURRENT_SESSION = (-1) Private Function GetStringFromLP(ByVal StrPtr As Long) As String Dim b As Byte Dim tempStr As String Dim bufferStr As String Dim Done As Boolean Done = False Do ' Get the byte/character that StrPtr is pointing to. CopyMemory b, ByVal StrPtr, 1 If b = 0 Then ' If you've found a null character, then you're done. Done = True Else tempStr = Chr$( ' Get the character for the byte's value bufferStr = bufferStr & tempStr 'Add it to the string StrPtr = StrPtr + 1 ' Increment the pointer to next byte/char End If Loop Until Done GetStringFromLP = bufferStr End Function Public Function GetMachinenameofCurrentSession() As String Dim RetVal As Long 'Return Value of API Call Dim lpBuffer As Long 'Buffer to Hold Info Returned Dim Count As Long 'Length of Buffer info Dim MachineName As String 'If the function succeeds, the return value is a nonzero value. 'If the function fails, the return value is zero. 'To get extended error information, call GetLastError API. RetVal = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _ WTS_CURRENT_SESSION, _ WTSClientName, _ lpBuffer, _ Count) MachineName = GetStringFromLP(lpBuffer) WTSFreeMemory lpBuffer 'Free the memory used by the buffer. GetMachinenameofCurrentSession = MachineName End Function Public Function GetIPofClientSession() As String Dim lRet As Long Dim Ret As Long Dim wca_Tmp As WTS_CLIENT_ADDRESS Dim pBytesReturned As Long Dim ppBuffer As Long Dim m_IpAddress As String ' IP address information for a session is bogus unless the session ' is a connected remote session. lRet = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _ WTS_CURRENT_SESSION, _ WtsClientAddress, _ ppBuffer, _ pBytesReturned) If lRet Then CopyMemory wca_Tmp, ppBuffer, pBytesReturned WTSFreeMemory ppBuffer m_IpAddress = Join(Array(wca_Tmp.Address(2), _ wca_Tmp.Address(3), _ wca_Tmp.Address(4), _ wca_Tmp.Address(5)), ".") Else m_IpAddress = vbNullString End If GetIPofClientSession = m_IpAddress End Function 'End Module "Mike Pratt" <MikePr...@discussions.microsoft.com> wrote in message news:24F7ACE4-EAC7-426A-86B2-CF7271A97910@microsoft.com... And here is my attempt at converting the part i need to autoit: CODElocal $returned, $addr $TSCall = DllCall("Wtsapi32.dll", "Int", "WTSQuerySessionInformationW", _ "ptr", "WTS_CURRENT_SERVER_HANDLE", _ "int*", "WTS_CURRENT_SESSION", _ "Int*", "WTSClientAddress", _ "str", $addr, _ "Int*", $returned) MsgBox(0, '', $TSCall[0]) But as this doesn't return anything I can't do anything with it. Can somebody help me out with this?
  3. Ok, I tried that, but when i run the script the usb drive is already unplugged. Instead I've come up with this: While 1 $objEvent = $colEvents.NextEvent If $objEvent.TargetInstance.DriveType = 2 Then If $objEvent.Path_.Class () = "__InstanceDeletionEvent" Then RunWait(@ComSpec & " /c kill.exe list g:\ > C:\Process.txt", "", @SW_HIDE) $file = ('c:\process.txt') $sRead = FileRead($file) $proc = StringRegExp($sRead, '[0-9]+', 3) For $iCC = 0 To UBound($proc) - 1 RunWait(@ComSpec & " /c kill.exe " & $proc[$iCC], "", @SW_HIDE) Next _RefreshSystemTray() ;Cleanup FileClose($file) FileDelete($file) ExitLoop EndIf EndIf WEnd I needed to be able to find the path / process Id from running programs while the drive was unplugged and kill.exe does this. http://www.mayabase.nl/index.php?PageID=29 I will probably end up moving the temp file to a temp dir, and haveing part of the script give the drive a specific letter no matter what machine it is plugged into. But for now it's looking good
  4. I can't seem to find an edit button on here. Anyway, the run taskkill.exe was an old command. I'm using: Run(@ComSpec & " /c " & 'kill.exe -f PortableAppsMenu.exe', "", @SW_HIDE)
  5. Hi, I am trying to write a script that will run when I plug in my USB stick, wait in the background, and then close all the programs that were opened from the stick when I unplug it. I've gotten the script to work and run fine, but I have to manually specify the programs to close in the script or in a text file. Is there any way to close all programs associated with a drive letter or folder? For example, close all programs with a path reference of G:\Folder\ This is what I have so far: ;========================================================= ;USB Insert ; ;calls process to kill processes on usb drive unplug ;as well as calls portable apps menu. ; ;========================================================= #NoTrayIcon FileInstall(".\USB Remove.exe", @TempDir & '\', 1) Run(".\StartPortableApps.exe", "", @SW_HIDE) Run(@TempDir & "\USB Remove.exe", "", @SW_HIDE) Exit ;========================================================= ;USB Remove ; ;Kills processes attached to usb device on unplug ; ;========================================================= #NoTrayIcon FileInstall(".\taskkill.exe", @TempDir & '\', 1) ;$path = ("G:\PortableApps\") $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") While 1 $objEvent = $colEvents.NextEvent If $objEvent.TargetInstance.DriveType = 2 Then If $objEvent.Path_.Class () = "__InstanceDeletionEvent" Then ;Run(@TempDir & "\Kill.exe killbypath " & $path & "PortableAppsMenu\PortableAppsMenu.exe", "", @SW_HIDE) Run(@TempDir & "\taskkill.exe /F /IM PortableAppsMenu.exe", "", @SW_HIDE) Run(@TempDir & "\taskkill.exe /F /IM gaim.exe", "", @SW_HIDE) Run(@TempDir & "\taskkill.exe /F /IM skype.exe", "", @SW_HIDE) _RefreshSystemTray() ExitLoop EndIf EndIf WEnd ; =================================================================== ; _RefreshSystemTray($nDealy = 1000) ; ; Removes any dead icons from the notification area. ; Parameters: ; $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's ; "Hide Inactive Icons" feature (In milliseconds). ; Returns: ; Sets @error on failure: ; 1 - Tray couldn't be found. ; 2 - DllCall error. ; =================================================================== Func _RefreshSystemTray($nDelay = 1000) ; Save Opt settings Local $oldMatchMode = Opt("WinTitleMatchMode", 4) Local $oldChildMode = Opt("WinSearchChildren", 1) Local $error = 0 Do; Pseudo loop Local $hWnd = WinGetHandle("classname=TrayNotifyWnd") If @error Then $error = 1 ExitLoop EndIf Local $hControl = ControlGetHandle($hWnd, "", "Button1") ; We're on XP and the Hide Inactive Icons button is there, so expand it If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) Sleep($nDelay) EndIf Local $posStart = MouseGetPos() Local $posWin = WinGetPos($hWnd) Local $y = $posWin[1] While $y < $posWin[3] + $posWin[1] Local $x = $posWin[0] While $x < $posWin[2] + $posWin[0] DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y) If @error Then $error = 2 ExitLoop 3; Jump out of While/While/Do EndIf $x = $x + 8 WEnd $y = $y + 8 WEnd DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1]) ; We're on XP so we need to hide the inactive icons again. If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) EndIf Until 1 ; Restore Opt settings Opt("WinTitleMatchMode", $oldMatchMode) Opt("WinSearchChildren", $oldChildMode) SetError($error) EndFunc ;==>_RefreshSystemTray
  6. I looked at that script, but that won't detect a USB drive that was plugged in before the script starts. The drives I'm trying to ignore are always plugged in, and only removed once in a blue moon. It also doesn't detect the hard disks being plugged in / unplugged. It detects USB sticks no problem though.
  7. No, I tried removable and no drives came up until i plugged in a usb stick. I think I may have found a way around it by disabling all usb devices using devcon before i check for drive letters, then enabling them again after. It's messy though and I'd prefer to do it without disabling them.
  8. I am trying to write a backup script that will log onto a network machine, grab the drive letters, and then back them up sequentially. That part works fine. The part I'm having problems is that when it grabs the drive letters it also grabs any USB Mass Storage devices attached. These aren't USB keys or anything, they are actual usb hard drives. I've tried a few scripts from on here but they all see the usb devices as fixed disks. Is there a way I can exclude these from the list? CODEFunc _ComputerGetDrives(ByRef $aDriveInfo, $sDriveType = "FIXED") Local $drive $drive = DriveGetDrive($sDriveType) If NOT @error Then Dim $aDriveInfo[uBound($drive)][6] $aDriveInfo[0][0] = $drive[0] For $i = 1 To $aDriveInfo[0][0] Step 1 $aDriveInfo[$i][0] = StringUpper($drive[$i]) $aDriveInfo[$i][1] = DriveGetFileSystem($drive[$i]) If @error Then SetError(1, 2, 0) $aDriveInfo[$i][2] = DriveGetLabel($drive[$i]) If @error Then SetError(1, 3, 0) $aDriveInfo[$i][3] = DriveGetSerial($drive[$i]) If @error Then SetError(1, 4, 0) $aDriveInfo[$i][4] = DriveSpaceFree($drive[$i]) If @error Then SetError(1, 5, 0) $aDriveInfo[$i][5] = DriveSpaceTotal($drive[$i]) If @error Then SetError(1, 6, 0) Next Else SetError(1, 1, 0) EndIf EndFunc ;_ComputerGetDrives Dim $Drives _ComputerGetDrives($Drives) ;Defaults to "FIXED" Local $backup = ("c:\backup.ini") FileOpen($backup,1) FileWrite($backup, '[Drives]' & @CRLF) For $i = 1 To $Drives[0][0] Step 1 FileWrite($backup, 'Drive=' & $Drives[$i][0] & @CRLF) Next $Drives = "All" _ComputerGetDrives($Drives) ;Defaults to "FIXED" Local $backup = ("c:\backup.ini") FileOpen($backup,1) FileWrite($backup, '[Drives]' & @CRLF) For $i = 1 To $Drives[0][0] Step 1 FileWrite($backup, 'Drive=' & $Drives[$i][0] & @CRLF) Next Note: This is from the CompInfo UDFs as it works well for what it does
×
×
  • Create New...