This question already has answers here:
Python - How to open Windows share using user name and password
(4 answers)
Closed 5 years ago.
How do I open Windows share with credentials using Python on a Windows machine?
I'm currently doing this:
share = open(r'share#username:password','r')
i used
subprocess.call(r'net use z: \windows_server\share /user:#username password', shell=True)
to mount the share and
subprocess.call(r'net use z: /delete')
to delete it.This is the most hassle free and efficient way. Thanks everyone for the help!!
Related
This question already has answers here:
C++: check if computer is locked
(5 answers)
Closed 3 years ago.
I want to create a program that "locks" my work station as soon as I leave or move away from my computer. And automatically starts again as soon as the user login.
I'm using Opencv to track my movement and its working.
now I want to know how can I automatically start a function again as soon as the user login using c++
I'm using
LockWorkStation();
to lock my system
I have a C# implementation for it which I got from
Programmatically Determine a Duration of a Locked Workstation?
const int SessionUnlockParam = 0x8;
if (m.WParam.ToInt32() == SessionUnlockParam)
{OnSessionUnlock(); // Do something when unlocked
}
void OnSessionUnlock()
{
// Do something......
}
can someone tell me how to to do this in C++
and which libraries to use
or
How can I access Event IDs in C++
such as: " Event_ID = 4801 - The workstation was unlocked".
for windows 8
You can register a window to receive events for session changes using WTSRegisterSessionNotification.
Then listen for WM_WTSSESSION_CHANGE with a wParam value of WTS_SESSION_UNLOCK.
This question already has answers here:
Downloading HTTP URLs asynchronously in C++
(4 answers)
Closed 8 years ago.
What I want my program to do is to download data from URL(this will be some text, code, whatever) and save it to string in C++. How do I do this? I googled a lot and found absolutely nothing, except using some classes that exist only on Linux. I'm working on Windows so I don't accept answers such as: use curl.h . Thanks
There are some POCO libraries that make it very easy. Here is some code that reads a single line of text from a website:
#include "Poco/URIStreamOpener.h"
#include "Poco/Net/HTTPStreamFactory.h"
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::URIStreamOpener& opener = Poco::URIStreamOpener::defaultOpener();
try
{
std::auto_ptr<std::istream> reader(opener.open(myURL));
reader->getline(line,sizeof(line));
}
catch(...)
{
}
And that's all there is to it. The try...catch is there in case of a bad Internet connection.
This question already has answers here:
How to get OS language using C++ API?
(3 answers)
Closed 8 years ago.
How to get the current default set language of the current Windows OS for version 7 and later versions using C++?
To deal this, I've tried to look for in the net but without any result.
Any brilliant suggestion, please?
Thanks a lot!
You can call GetUserDefaultLocaleName to get the locale
string const s = setlocale( LC_ALL, "" );
cout << s << endl;
… is one way.
Update: The above does not retrieve the “preferred” language set in the Control Panel. E.g. on my laptop it says Norwegian in spite of a preference for US English. Following the documentation I tried GetSystemPreferredUILanguages, but it still reported Norwegian. However, GetThreadUILanguage reports US English, so presumably that's it.
This question already has answers here:
Using C++ to edit the registry
(5 answers)
Closed 9 years ago.
I will write this registry key in the registry.
It should be written in C++ for windows 7 and 8.
This is the .reg file:
REGEDIT4
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\.bin\]
[-HKEY_CLASSES_ROOT\binimage\]
[-HKEY_CLASSES_ROOT\Bootvis Trace File\]
[-HKEY_CLASSES_ROOT\Crestron SIMPL Windows Compiled Program\]
[-HKEY_CLASSES_ROOT\elby.VCDMount.1\]
[-HKEY_CLASSES_ROOT\gBurner\]
[-HKEY_CLASSES_ROOT\ImgBurn.AssocFile.bin\]
[-HKEY_CLASSES_ROOT\IsoBuster.bin\]
[-HKEY_CLASSES_ROOT\IZArcBIN\]
[-HKEY_CLASSES_ROOT\MPlayerFileVideo\]
[-HKEY_CLASSES_ROOT\PAISO\]
[-HKEY_CLASSES_ROOT\StuffIt.Archive.Open.Generic\]
[-HKEY_CLASSES_ROOT\StuffIt11.Archive.Open.Generic\]
[-HKEY_CLASSES_ROOT\TzBIN\]
[-HKEY_CLASSES_ROOT\UltraEdit.bin\]
[-HKEY_CLASSES_ROOT\VLC.bin\]
[HKEY_CLASSES_ROOT\.bin\]
#="exefile"
"Content Type"="application/x-msdownload"
[HKEY_CLASSES_ROOT\.bin\PersistentHandler\]
#="{098f2470-bae0-11cd-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT\.bin\shell\open\command\]
#="\"%1\" %*"
IDK how to do it but maybe anyone here can help me :)
Thanks :)
You should use the WinAPI functions for registry handling. You can find the list here.
I would be checking these functions:
RegCreateKeyEx
RegOpenKeyEx
RegGetValue
RegSetValueEx
RegCloseKey
This question already has answers here:
system("c:\\sample\\startAll.bat") cannot run because of working directory?
(4 answers)
Closed 9 years ago.
Consider the following:
I have a c++ program in C:\Documents\myProgram.exe
With this code in it:
system("start C:\\somefolder\\start.bat");
That will start the target file (start.bat) in C:\Documents\ instead of `C:\somefolder\'.
My question is, how do I execute the file in it's own directory instead of myProgram's directory?
In theory this is what I want to accomplish using c++:
cd C:\somefolder\,
start start.bat
If you're on windows anyway, use ShellExecute, you can set more things and launch even documents, links etc.
To do this you can do one of two things (that I found).
A) You can use chdir() in unistd.h; see http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html
or
B) You can use something called the File System Interface, from the GNU library, for more advanced stuff; see http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface.
Anyway, best of luck, I hope you find something that will work!