why is my code failing to run a simple executable using WinRM's C++ API?
//main.cpp
int main()
{
ShellClient *shellClient = new ShellClient();
//Set up the shell client here and connect to the localhost.
//This seems to be working fine because I'm handling every
//possible error code, and none of them are being triggered
PCWSTR commandLine = L"\"MyExampleExecutable.exe\"";
isOk = shellClient->RunCommand(commandLine);
if (!isOk)
return 1;
return 0;
}
//ShellClient.cpp
bool ShellClient::RunCommand(PCWSTR command)
{
WSMAN_SHELL_ASYNC createCommandAsync;
ZeroMemory(&createCommandAsync, sizeof(createCommandAsync));
createCommandAsync.operationContext = this;
createCommandAsync.completionFunction = (WSMAN_SHELL_COMPLETION_FUNCTION)CommandCreatedCallback;
WSManRunShellCommand(shellHandle, 0, command, NULL, NULL, &createCommandAsync, &commandHandle);
if (commandHandle == NULL)//It is *always* NULL
{
std::cout << "command handle null" << std::endl;
system("pause");
return false;
}
return true;
}
One possible clue is that my C++ code thinks the shell gets created fine, but in the Event Viewer for my machine, there is this:
WSMan operation CreateShell failed, error code 2150859250
At the time of writing, this lovely error code gives precisely zero results when put into Google, making it rather difficult to know what it means.
Background and common solutions which I have already checked
As documented here and explaned in this video by the same author, most WinRM issues boil down to either connection or authentication problems. In my case, if I deliberately enter incorrect user credentials, I get an authentication error, so I know that my program is connecting and authenticating fine when the correct username and password are supplied. Also:
From the command line, I can connect to my local machine and pretend it's a remote server, for example the following command works fine:
winrs -r:http://localhost:5985 -u:COMPUTERNAME\Jeremy "dir"
winrm quickconfig shows the service is working (which we already know otherwise the winrs command wouldn't work)
winrm get winrm/config shows TrustedHosts = localhost, AllowUnencrypted = true, and all authentication methods are set to true
Following this advice, I have set the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy = 1
Working in Windows 10
Thank you in advance!
I wasn't aware of this so can't comment on whether it's common knowledge but Microsoft have a nifty error lookup tool where you can enter an error code (after converting it from a normal number to hexadecimal) and it tells you what it means.
In this case, 2150859250 (803381F2 in hex) corresponds to:
ERROR_WINRS_IDLETIMEOUT_OUTOFBOUNDS wsmerror.h
# The WS-Management service cannot process the request. The
# requested IdleTimeout is outside the allowed range.
When setting up the WinRM shell, I was doing the following:
WSMAN_SHELL_STARTUP_INFO startupInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.idleTimeoutMs = 1000;//not large enough!
startupInfo.workingDirectory = L"C:\\";
//other parameters of startupInfo set here
WSManCreateShell(session, 0, shellUri, &startupInfo, NULL, NULL, &createShellAsync, &shellHandle);
Changing idleTimeoutMs from 1000 to a much larger number like 100000 solved the error and my program now works fine.
Since the official docs for this parameter say anything between 0 and 0xFFFFFFFF are valid, it remains a mystery why a value of 1000 is throwing this error. I leave this for somebody more knowledgable than myself to answer, on the off chance that they come across this question.
I'm actually try to use libgit2 with C++ to commit and push in a git repository.
No problem with HTTPS but with SSH I have the error :
git_remote_connect : Invalid command: 'XXX 'YYY/test.git''
You appear to be using ssh to clone a git:// URL.
Make sure your core.gitProxy config option and the
GIT_PROXY_COMMAND environment variable are NOT set
After long research I finally found where my problem normally comes from.
In git_remote_connect the third argument is a git_remote_callbacks.
I need to define a payload in this callbacks.
The payload need to be a git_strarray containing two string but I have absolutly no idea of what string I'm supposed to write. A shell command? A c++ function? An username?
If I don't add the payload in the callbacks, I have the error :
"invalid ssh paths, must be two strings"
I create a payload :
char * str1 = "";
char * str2 = "XXX"; //The string that appear in the error message
char * astr[2];
astr[0] = str1;
astr[1] = str2;
git_strarray payload = {astr, 2};
push_options.callbacks.payload = &payload;
My question is: Did you know what I'm supposed to write in the two string of the payload?
Solved
I solved my problem: I added transport to my callbacks, that's why that didn't work. Thank you Carlosmn for your patience!
There is a slack for libgit2, you can join it if you have problem: http://slack.libgit2.org/
I am trying to get started with Eventhubs using the following link https://azure.microsoft.com/en-us/documentation/articles/event-hubs-java-storm-getstarted/.
When I pass the connection string directly to the ConnectionStringBuilder( connectionString), then the program sends data to the Eventhub. I notice that the connection string
starts with Endpoint=sb://....
but when I use ConnectionStringBuilder(namespaceName, eventHubName, sasKeyName, sasKey), I notice that the connectionstring created
starts with Endpoint=amqps://
and the program doesn't work and gives the following error
com.microsoft.azure.servicebus.AuthorizationFailedException: Attempted to perform an unauthorized operation.
I missed the last char of the SaSKey and so It didn't work...Sorry for this question
I'm trying get the proxy settings for my computer automatically.
I've set up a local server and I've uploaded a .pac file (which I can access from my browser) and I've set the link to it in the Internet Explorer connection settings, in the "address" field and checked "Use automatic configuration script".
My code is the following:
int main()
{
LPWSTR str = NULL;
if (!WinHttpDetectAutoProxyConfigUrl(WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A, &str))
{
printf("%d\n", GetLastError());
}
if(str)
GlobalFree(str);
return 0;
}
The function always fails and GetLastError returns 12180 (ERROR_WINHTTP_AUTODETECTION_FAILED)
What am I doing wrong?
From https://developer.appcelerator.com/question/120622/errorwinhttpautodetectionfailed:
This error message is not necessarily a problem and can be ignored if you are using direct connection. you get this error if you are having direct connection. to check that and get more info, you can use the following commands:
cd windows\system32
netsh winhttp help
— answered 4 years ago by Nick G
From your comment I gather that this was indeed the reason you were getting this error, so I'm posting it as an answer.
I am using libcurl for a small program that gets data from an input url. But i sometimes get an error from the pErrorBuffer like:
Failed writing to body (something != somethingelse)
What does this mean? I mean in what situation is this error created?
It means your write callback didn't return the same number of bytes as was passed into it!