English 中文(简体)
WMI USable and Disable
原标题:WMI USB Enable and Disable
  • 时间:2012-01-12 11:47:17
  •  标签:
  • wmi

Hi I am using WMI to change the remote registry value for USBSTOR. I want to change the value of start attribute to 4 or 3 for enabling and disabling. But the datatype for Start attribute in registry is DWORD, if i can the datatype to size it does not work . I need to keep the Datatype to DWORD. Can someone please tell me how to setDWORDValue using WMI, following is the piece of code that i tried, it worked succesfully but still the value of start field is unchanged in registry.

const uint HKEY_LOCAL_MACHINE = 0x80000002;

ManagementBaseObject methodParams = registryTask.GetMethodParameters(typeOfValue);

methodParams["hDefKey"] = HKEY_LOCAL_MACHINE;// BaseKey;
methodParams["sSubKeyName"] = @"SYSTEM\CurrentControlSet\Servic\USBSTOR";
methodParams["sValueName"] = "Start";

try
{
    methodParams["sValue"] = "3";
}
catch
{
    methodParams["uValue"] = (UInt32)Convert.ToInt32("3");
}

ManagementBaseObject exitValue = registryTask.InvokeMethod(typeOfValue, methodParams, null);
问题回答

简单的解决办法使用假日。

import wmi
import win32api,_winreg

c = wmi.WMI()

# To get the binary value of particular subkey
# Please note that 0x80000002 represents HKEY_LOCAL_MACHINE 
ReturnValue, uValue = c.StdRegProv.GetBinaryValue(0x80000002,"AFD","SYSTEMCurrentControlSetServices")

# To get the list of all the subkeys available in particular key
ret, subKeys = c.StdRegProv.EnumKey (0x80000002, "SYSTEMCurrentControlSetServices")
print ret
for key in subKeys:
  print key

ReturnValue=c.StdRegProv.SetDWORDValue(0x80000002,"Type","SYSTEMCurrentControlSetServicesUSBSTOR",0x4)

#HKEY_CLASSES_ROOT (2147483648 (0x80000000))
#HKEY_CURRENT_USER (2147483649 (0x80000001))
#HKEY_LOCAL_MACHINE (2147483650 (0x80000002))
#HKEY_USERS (2147483651 (0x80000003))
#HKEY_CURRENT_CONFIG (2147483653 (0x80000005))
#HKEY_DYN_DATA (2147483654 (0x80000006))




相关问题
How can I query NTFS disk quotas in C#?

I need to be able to find, for all users on a given remote machine, those users disk quotas and actual disk usage. I need to be able to do this reporting in a C# application. (Well, technically a DLL ...

WMI Poor Performance

I wrote a code in C# that maps logical drives to their physical disks, using WMI (System.Management). The code working perfectly, but slow like hell. In my machine (Windows 7 x64, Dual-Core with 3 GB ...

Closing Open Files using C#

I have a situation where people are connected to files on a share and it s blocking me from overwriting the file. I m trying to write a method that will look to see if a filePath that I provide is ...

Binding an SSL certificate to a port programmatically

I m working on a self-hosted WCF service for which encrypted communications is an option. Everything works fine when a certificate is already bound to the port as described here. However, I want to ...

热门标签