habe die Idee durch diese beiden Links bekommen
http://forum.gleitz.info/archive/index.php/t-31177.html
https://social.msdn.microsoft.com/Forum ... windows7de
es geht um das entfernen eines USB Device und dafür benötige ich einen String in "dem" Format.
also dachte ich mir frage WMI ... aber nach "was" ?
es "müsste" irgendwas mit PnP zu tun haben und sich suche nach meinem USB Stick : "SanDisk Ultra USB"
Code: Alles auswählen
#include "common.ch"
#include "os.ch"
#define CRLF CHR(13)+CHR(10)
#PRAGMA LIBRARY("ASCOM10.LIB")
PROCEDURE GetPnP(strComputer,cUser,cPassword)
LOCAL objWMIServices
LOCAL colItems
LOCAL bCollBlock
LOCAL aitem := {}
DEFAULT strComputer TO "Localhost"
DEFAULT cUser TO "Administrator"
DEFAULT cPassword TO ""
IF VAL( OS(OS_VERSION) ) > 6
IF strComputer == "Localhost"
objWMIServices := CreateObject( "WbemScripting.SWbemLocator" ):ConnectServer(strComputer, "Root\CIMv2")
ELSE
IF EMPTY(cPassword)
MSGBOX("Need Password")
QUIT
ELSE
objWMIServices := CreateObject( "WbemScripting.SWbemLocator" ):ConnectServer(strComputer, "Root\CIMv2",strComputer+"\"+cUser,cPassword)
ENDIF
ENDIF
ELSE
objWMIServices := GetObject("WinMgmts:{impersonationLevel=impersonate}\\"+strComputer+"\Root\CIMv2")
ENDIF
colItems := objWMIServices:ExecQuery("select * from Win32_PnPEntity",,48)
bCollBlock := {|oService,n| AADD(aItem,{ n,;
oService:getProperty("Caption"),;
oService:getProperty("ClassGuid"),;
oService:getProperty("PNPDeviceID") })}
ComEvalCollection(colItems, bCollBlock )
objWMIServices:Release()
objWMIServices:destroy()
objWMIServices := NIL
bCollBlock := NIL
colItems := NIL
RETURN aitem
Code: Alles auswählen
PROCEDURE Main
LOCAL aWMI := GetPnP()
LOCAL nPosi := ASCAN(aWMI,{ |a| "SanDisk Ultra USB" $ a[1] } )
LOCAL cString
IF nPosi > 0
* cString := aWMO[nPosi][3] // "PNPDeviceID" -> USBSTOR\DISK&VEN_SANDISK&PROD_ULTRA_USB_3.0&REV_1.00\4C531001361105123391&0
cString := aWMO[nPosi][2] // "ClassGuid" -> {4d36e967-e325-11ce-bfc1-08002be10318}
Msgbox(cString)
also eine *.BAT mit der "ClassGuid"
Code: Alles auswählen
rundll32.exe C:\Windows\system32\hotplug.dll,HotPlugSafeRemovalNotification \\.\pipe\PNP_HotPlug_Pipe_1.{4d36e967-e325-11ce-bfc1-08002be10318}
warum klappt das nicht
jemand eine Idee