How can i make my program run automatically in python [closed] - python-2.7

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I export my python code by pyinstaller i need my program to startup automatically whith the windows (i don't need to do that by startup folder)

First you need to create a shortcut. This will create shortcut on your desktop
import os, sys
import pythoncom
from win32com.shell import shell, shellcon
shortcut = pythoncom.CoCreateInstance (
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
shortcut.SetPath (sys.executable)
shortcut.SetDescription ("Python %s" % sys.version)
shortcut.SetIconLocation (sys.executable, 0)
desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
persist_file.Save (os.path.join (desktop_path, "python.lnk"), 0)
You can make toany of windows locations for startup files ( or create it only in startup place) :
Run Once :HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
Run each Start: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
StartUp folder : C:\Documents and Settings\All Users\Start Menu\Programs\Startup
Shared Task Manager : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SharedTaskScheduler
Make it as a service, and make that service automatic started
To see what programs start automatically on your computer, or to add your entries easy, you can use autoruns from SysInternals, http://technet.microsoft.com/en-us/sysinternals/bb963902.aspx
P.S. Python example is from timgolden.me.uk site.

Related

check mariadb connection with c++ (without dependencies) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
I got myself a programm where a user types in their mariadb credentials (username/password/port).
I now want the programm to check if this connection is working or if something is wrong.
Right now I am running processes with CreateProcess but since statements like mysql -u root -pwrongpassword will still run through without any errors, this doesn't work.
I want such a statement, or just a generic connection check, to return false when those credentials turn out as wrong.
Important here is that it has to work without any existing software on the target system (except mariadb if necessary for your solution).
What would be a solid practice for that task?
Reinventing the wheel (as suggested by Sam Varshavchik) is not a good idea: It's not just opening a socket, writing and reading data. Depending on the authentication options you have to support SSL/TLS and the various authentication methods (native password, ed25519, sha256_caching_password, sha256_password, gssapi/kerberos) which is quite complex.
Since you mentioned that MariaDB is installed on your target system, you can use the mariadb client library (MariaDB Connector/C), which is also used by mysql command line client. It is installed together with the server package.
#include <mysql.h>
int check_connection(const char *user, const char *password, int port)
{
int rc= 0;
MYSQL *mysql= mysql_init(NULL);
if (mysql_real_connect(mysql, "localhost", user, password, NULL, port, NULL, 0))
rc= 1;
mysql_close(mysql);
return rc;
}
Now you have to link your application against libmariadb.lib (dynamic linking) or mariadbclient.lib (static linking).

Packing a DLL into an exe and deleting it after running [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to pack a dynamic link library (D L L) into an executable and when I run it I want it to be deleted from the hard drive.
so the first question i need help with is: How to PROPERLY add a D L L into my project? so when i build it, the D L L is in the executable?
and the second question is: once the D L L is properly included in the project & the project is build into an executable, i want the D L L to be injected to another process from the executable using the following code:
pastebin.com/zsYVMqvs
and now to the third question: once the D L L is injected & it has to be extracted somewhere right? so i would like to delete the extracted D L L instantly after injecting so it does not stay there.
Putting the DLL into the resources of your .exe is a possibility. You then need to extract the DLL from the resources to a dll file on the local hard drive, probably into the temp directory. Then use it. Before the program quits, delete the dll created beforehand.
To extract use FindResource, LoadResource, LockResource and SizeofResource .
Flow of operations:
Extract the DLL to the TEMP directory (use GetTempPath)
run program doing whatever stuff you want to do with the DLL
befor the program quit make sure the DLL isn't used any more
delete the dll created under 1.

The correct way to make my program run at startup [duplicate]

This question already has answers here:
How to run a program automatically as admin on Windows 7 at startup?
(9 answers)
Closed 4 years ago.
(1) I want to make my program run at startup. I did that step:
I added my program path to that registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run [Or]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Previously, the program was running at startup but after I have added the Manifest File to give my program the administrative privileges as follow:
Since that action, the program doesn't run at startup.
Finally, the code which adds the value to Software\\Microsoft\\Windows\\CurrentVersion\\Run:
// Set launch at startup setting
bool startup = wxAtoi(CPublic::getConfigItem("settings/startup"));
wxString appName = wxTheApp->GetAppName();
wxRegKey regKey(wxRegKey::HKCU, "Software\\Microsoft\\Windows\\CurrentVersion\\Run");
if (startup == 1) {
regKey.SetValue(appName, wxStandardPaths::Get().GetExecutablePath());
} else {
regKey.DeleteValue(appName);
}
What's the problem then?
(2) There is another simple question related to that question:
How to make my program hides after running at startup into the system tray?
To answer the 2nd question (the 1st one is answered in the comment by #Snetfel above), you simply need to create a wxTaskBarIcon and avoid creating any (visible) normal windows on startup.

Why file is not created in /etc/ directory [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Please find the code sample
void createFile(const std::string& FileName, const std::string& Content)
{
ofstream of(FileName.c_str());
of<<Content;
of.close();
}
const std::string testFile = "/etc/testFile";
const std::string EmptyContent = "";
createFile(testFile, EmptyContent);
File is not creating at /etc/ directory. I think this is related to permissions. What extra I have to add in the code to work.
There's nothing extra that you can add to this program to "make it work". If an arbitrary program can write to /etc, this would toss the traditional POSIX security model out the window.
In order to be able to write to /etc, your program must be executed as root.
It seems to be a permission issue. Try to run your program using sudo:
sudo yourprogram

Coredump Analysis [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have observed a core dump on a UNIX server and have to analyze the cause behind it.
Following is the output of coredump using mdb
Loading modules: [ libc.so.1 libuutil.so.1 ld.so.1 ]
> ::status
debugging core file of pmr_colld_aos (32-bit) from atrcxb2532
file: /opt/ericsson/aos/PDM/bin/pmr_colld_aos
initial argv: /opt/ericsson/aos/PDM/bin/pmr_colld_aos -ORBInitRef NameService=corbaloc::maste
threading model: multi-threaded
status: process terminated by SIGABRT (Abort)
> ::stack
libc.so.1`_lwp_kill+0x15(1, 6)
libc.so.1`raise+0x1f(6)
libc.so.1`abort+0xcd(8026ad0, 8eb2d88, 0, fe2cb9d0, 8ea9f50, 80275b0)
libstdc++.so.6.0.3`_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xdf(fe2eb0c0, fe2cb9d0, 8026a78, fe2b53cc, fe2b7298, 8ea9f50)
libstdc++.so.6.0.3`_ZN10__cxxabiv111__terminateEPFvvE+0x14(fe2b7298, 8ea9f50, 8026a88, fe2b467a, feffd888, fe2cb9d0)
libstdc++.so.6.0.3`_ZN10__cxxabiv112__unexpectedEPFvvE(1, fe2cb9d0, 8026af8, fe2b52d6, fe2b53ac, fe217a44)
libstdc++.so.6.0.3`_ZN10__cxxabiv112__unexpectedEPFvvE+0x14(fe2b53ac, fe217a44, feffa320, 0, 8026ad8, fe2b7298)
libstdc++.so.6.0.3`__cxa_call_unexpected+0x42(8ea9f80, 8026b40, 8c70120, 82aa448, 8e382a8, 8026b20)
_ZN21PDRFileTimeoutHandler5checkEv+0xa10(fe17f000, fdfa2a00, 8026c90, fe0a5bf6, fe180680, 0)
main+0x1309(2, 8026e10, 8026e24)
_start+0x80(4, 8027618, 8027682, 802764c, 8027640, 0)
> $C
080269c4 libc.so.1`_lwp_kill+0x15(1, 6)
080269dc libc.so.1`raise+0x1f(6)
08026a28 libc.so.1`abort+0xcd(8026ad0, 8eb2d88, 0, fe2cb9d0, 8ea9f50, 80275b0)
08026a48 libstdc++.so.6.0.3`_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0xdf(fe2eb0c0, fe2cb9d0, 8026a78, fe2b53cc, fe2b7298, 8ea9f50)
08026a58 libstdc++.so.6.0.3`_ZN10__cxxabiv111__terminateEPFvvE+0x14(fe2b7298, 8ea9f50, 8026a88, fe2b467a, feffd888, fe2cb9d0)
08026a78 libstdc++.so.6.0.3`_ZN10__cxxabiv112__unexpectedEPFvvE(1, fe2cb9d0, 8026af8, fe2b52d6, fe2b53ac, fe217a44)
08026a88 libstdc++.so.6.0.3`_ZN10__cxxabiv112__unexpectedEPFvvE+0x14(fe2b53ac, fe217a44, feffa320, 0, 8026ad8, fe2b7298)
08026af8 libstdc++.so.6.0.3`__cxa_call_unexpected+0x42(8ea9f80, 8026b40, 8c70120, 82aa448, 8e382a8, 8026b20)
08026c68 _ZN21PDRFileTimeoutHandler5checkEv+0xa10(fe17f000, fdfa2a00, 8026c90, fe0a5bf6, fe180680, 0)
08026dec main+0x1309(2, 8026e10, 8026e24)
08026e04 _start+0x80(4, 8027618, 8027682, 802764c, 8027640, 0)
> $G
C++ symbol demangling enabled
> ::quit
Can anyone help me in understanding this output?
Please note that the code has been written in the pmr_colld_aos in directory - /opt/ericsson/aos/PDM/bin/pmr_colld_aos.
Also, I just want to know how to understand such outputs which will help me in backtracing the code.
What you got there is the backtrace of the crash. The last routine that's part of the program was FileTimeoutHandler5checkEv() so it's likely that the error is in there. Everything after this point is part of the C++ library.
But if you really want to examine it, then you should load the core file into GDB along with the program that caused it. It's way easier than examining the core file with mdb.