简体   繁体   English

如何使用C ++获取计算机ID

[英]How to get Machine id using c++

am facing two problems one big problem and one small problem :) problem # 1 : am unable to read Machine ID from below path ... i get my processor name like intel i7 @2.2ghz like that , i do not know why , i should get machine id , long integer string but i not get it , so please help 我面临两个问题,一个大问题和一个小问题:)问题#1:无法从路径下方读取计算机ID ...我像这样获得处理器名称,如intel i7 @ 2.2ghz,我不知道为什么,我应该得到机器ID,长整数字符串,但是我没有,所以请帮忙

  reg_path="SOFTWARE\\Microsoft\\Cryptography";    
  rvalue="MachineGuid";  // data value

my registery reading function 我的阅读功能

   string read_reg_sz(char rpath[],char rdata[])    // read registery Loaction
{
    REGSAM flag = KEY_WOW64_32KEY or KEY_WOW64_64KEY; 
    char buffer[MAX];   
    char Buffer[MAX];
    DWORD BufSize = _MAX_PATH;
    char dwMHz[MAX];
    DWORD dataType = REG_SZ;       
    HKEY hKey;
    long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,rpath,NULL, KEY_READ | KEY_WRITE | flag,&hKey);
    if(lError != ERROR_SUCCESS)
      {// if the key is not found, tell the user why:
           FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
                         NULL,
                         lError,
                         0,
                         Buffer,
                         _MAX_PATH,
                         0);
            cout<<"\n reg erro : "<<Buffer;
           return "N/A";
       }
        // query the key:
        RegQueryValueEx(hKey,rdata,NULL,&dataType,(LPBYTE) &dwMHz,&BufSize);
    RegCloseKey(hKey);  // close open handle ....
    cout<<"\n reg data read: "<<dwMHz;
return dwMHz;
}

second problem : currently i have function which can totally clean recycle bin :) 第二个问题:当前我具有可以完全清洁回收站的功能:)

SHEmptyRecycleBin(NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND); 

but i want to delete single file from recycle bin like passing filename 但我想从回收站中删除单个文件,如传递文件名

You should really post it as two different questions, but I'll try to answer both. 您实际上应该将其发布为两个不同的问题,但我会尽力回答两个问题。

1. Get MachineGuid 1.获取MachineGuid

I think your issue is in this line: 我认为您的问题在以下方面:

    // query the key:
    RegQueryValueEx(hKey,rdata,NULL,&dataType,(LPBYTE) &dwMHz,&BufSize);

You should change it to: 您应该将其更改为:

    // query the key:
    RegQueryValueEx(hKey,rvalue,NULL,&dataType,(LPBYTE) &dwMHz,&BufSize);

By the way, dhMHz does not sound like right variable name - change it to reflect reality. 顺便说一句,dhMHz听起来不像正确的变量名-更改它以反映现实。

Also, you should have this: 另外,您应该具有以下内容:

 DWORD BufSize = sizeof(Buffer) - 1;

And, it would be nice to NOT have both buffer and Buffer variables. 而且,最好不要同时具有bufferBuffer变量。

2. Delete one file from recycle bin 2.从回收站中删除一个文件

According to Microsoft documentation on SHFileOperation, you should just use DeleteFile on filename like C:\\$Recycle.Bin\\file.txt : 根据Microsoft关于SHFileOperation的文档 ,您应该仅对文件名使用DeleteFile ,例如C:\\$Recycle.Bin\\file.txt

  • When used to delete a file, SHFileOperation permanently deletes the file unless you set the FOF_ALLOWUNDO flag in the fFlags member of the SHFILEOPSTRUCT structure pointed to by lpFileOp. 当用于删除文件时,除非在lpFileOp指向的SHFILEOPSTRUCT结构的fFlags成员中设置FOF_ALLOWUNDO标志,否则SHFileOperation会永久删除该文件。 Setting that flag sends the file to the Recycle Bin. 设置该标志会将文件发送到回收站。 If you want to simply delete a file and guarantee that it is not placed in the Recycle Bin, use DeleteFile . 如果您只想删除文件并确保未将其放置在回收站中,请使用DeleteFile

要从回收站中删除单个文件,请使用SHGetSpecialFolderLocation(CSIDL_BITBUCKET)SHGetKnownFolderIDList(FOLDERID_RecycleBinFolder)获取回收站的绝对PIDL,然后使用SHBindToObject()获取其IShellFolder接口,并将其ParseDisplayName()方法ParseDisplayName()将所需的文件名转换为相对的PIDL,然后使用SHBindToObject()获取文件的IContextMenu接口,并调用其InvokeCommand()方法以执行文件的“删除”动词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM