Comments (4)
I also encountered this problem, I fixed it in the following way, parsing the command directly at the dart layer.
final process = await Process.start(
'wmic',
['csproduct', 'get', 'UUID'],
mode: ProcessStartMode.detachedWithStdio,
);
final result = await process.stdout.transform(utf8.decoder).toList();
String? deviceID;
for (var element in result) {
final item = element.replaceAll(RegExp('\r|\n|\\s|UUID|uuid'), '');
if (item.isNotEmpty) {
deviceID = item;
}
}
debugPrint('uuid: $deviceID');
Referring to Unity deviceUniqueIdentifier , I generated a Flutter deviceUniqueIdentifier in windows platfrom, hope it help.
Update: 2022-05-11
from platform_device_id.
To avoid terminal windows showing up, I change void PlatformDeviceIdWindowsPlugin::HandleMethodCall
in platform_device_id/platform_device_id_windows/windows/platform_device_id_windows_plugin.cpp
to following:
void PlatformDeviceIdWindowsPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
std::string strResult;
std::string deviceId;
if (method_call.method_name().compare("getDeviceId") == 0) {
std::string cmd = "wmic csproduct get UUID";
HANDLE hPipeRead, hPipeWrite;
SECURITY_ATTRIBUTES saAttr = {sizeof(SECURITY_ATTRIBUTES)};
saAttr.bInheritHandle = TRUE; // Pipe handles are inherited by child process.
saAttr.lpSecurityDescriptor = NULL;
CreatePipe(&hPipeRead, &hPipeWrite, &saAttr, 0);
STARTUPINFOW si = {sizeof(STARTUPINFOW)};
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.hStdOutput = hPipeWrite;
si.hStdError = hPipeWrite;
si.wShowWindow = SW_HIDE; // Prevents cmd window from flashing.
PROCESS_INFORMATION pi = { 0 };
BOOL fSuccess = CreateProcessW(NULL, (LPWSTR)towstring(cmd).c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
if (! fSuccess) {
CloseHandle(hPipeWrite);
CloseHandle(hPipeRead);
} else {
bool bProcessEnded = false;
for (; !bProcessEnded ;) {
// Give some timeslice (50 ms), so we won't waste 100% CPU.
bProcessEnded = WaitForSingleObject( pi.hProcess, 50) == WAIT_OBJECT_0;
// Even if process exited - we continue reading, if
// there is some data available over pipe.
for (;;)
{
char buf[1024];
DWORD dwRead = 0;
DWORD dwAvail = 0;
if (!::PeekNamedPipe(hPipeRead, NULL, 0, NULL, &dwAvail, NULL) || !dwAvail || !::ReadFile(hPipeRead, buf, min(sizeof(buf) - 1, dwAvail), &dwRead, NULL) || !dwRead)
break;
buf[dwRead] = 0;
strResult += buf;
}
}
CloseHandle(hPipeWrite);
CloseHandle(hPipeRead);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
std::size_t pos = strResult.find("\n");
deviceId = strResult.substr(pos+1);
result->Success(flutter::EncodableValue(deviceId));
} else {
result->NotImplemented();
}
}
This solution works for me.
from platform_device_id.
build error C2660: 'CreateProcessW': function does not take 9 arguments [D:\Project\App\Flutter\app-desktop\build\windows\plugins\platform_device_id_windows\platform_device_id_windows_plugin.vcxproj]
BOOL fSuccess = CreateProcessW(NULL, (LPWSTR)towstring(cmd).c_str(), NULL, 0, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
from platform_device_id.
Related Issues (20)
- Consider use fingerprintjs in web HOT 1
- Desktop implementations would be simplified
- Error on Linux HOT 3
- Getting same id on different devices.
- build fails on Mac
- hi thanks for the package, one question
- Failure in Ubuntu 20.04
- Replace device_info with device_info_plus HOT 1
- Lost connection to device HOT 8
- [platform_device_id_platform_interface] Function is not implemented HOT 1
- platform_device_id_windows_plugin.dll is not found
- Returning "" on Windows platform HOT 2
- platform_device_id-1.0.1 depends on discontinued package: device_info HOT 3
- Better clarification of what is device id
- Link to repo is missing in pub.dev
- platform_device_id does not work in pure Dart
- Android Build Error HOT 4
- Get to the special characters on Windows platform HOT 5
- Getting error if imports this package HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from platform_device_id.