I want to read some eventlog files with python over wmi. actually I can read event logs like System, Application, Security, InternetExplorer, PowerShell. But I cant access the eventlog file for the remotedesktop.
Currently Python script:
python_script
The function check_vnc_services works. My problem is, that I cant open the eventlog for remotedesktop. I also tried it with C# and C++. I cant access it:
eventlog file that I will open
Also the WMI Code Generator didn't show me such microsoft files:
enter image description here
I hope that someone can told me how I can access this rpd event log file. Suddenly I think that I maybe using a wrong WMI?
Related
I started learning Python this week, and I am trying to automate adding a new user to both active directory, and on Office 365.
I have managed to add the user to AD using a client and a bot, and also use another script to generate the correct New-MsolUser syntax for Powershell.
How do I get Python to open Powershell and run the output of "o365command"?
Also will I need to connect to the tenant every time I do this so will I need to incorporate this into the script as well?
Happy to show the code I have if needed.
If you provide the output from Python as JSON to a file, then PowerShell can import that directly. See ConvertFrom-Json (ConvertFrom-Json).
As for running PowerShell from Python, look at: Running an outside program (executable) in Python?
It's not something I've ever tried but good luck.
Been trying to get this working all day, and i just can't figure out why its not working.
Trying to implement a simple trigger to run when the user submitted a file.
example in the .tmp file:
hello_trigger change-submit //testDepot/... "python F:/triggers/hello_trigger.py"
when i try to submit a file i get this:
Submit validation failed -- fix problems then use 'p4 submit -c 10199'.
'hello_trigger' validation failed: python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
File exists and can be read, so its not a python issue.. same error with a .txt or .bat file.
From what i can gather the problem seems to be coming from the depot line in the trigger.
//testDepot/... fails
//depot/... doesnt fail, but the script is never fired off.
Any suggestions are greatly appreciated.
also testDepot is a stream not sure if that matters.
python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
seems pretty clear that the file doesn't exist, at least from the point of view of this trigger command. Some things to double check:
This is running on the server machine, i.e. the place where the p4d service is running. If you have the script on your client machine the Python executable on the server isn't going to be able to find it!
Similarly, this is being run by whatever user is running p4d (on Windows this is usually the SYSTEM user, which may have limited permissions). Does that user have permission to read this path?
Could it be that your version of Python on Windows doesn't know how to handle paths with Unix-style forward slashes? (Many tools will normalize these for you but you shouldn't depend on it!) Try using a valid Windows path, i.e. F:\triggers\hello_trigger.py.
I've setup Geany a long time ago to compile my Python program on my Windows machine which it then sends to my Pi via scp. It still works fine - but if I take the same file and rename it, it refuses to do it.
I get "scp: /home/pi/scripts/APC2.py: Permission denied" from the Compiler in the MEssage window
And really don't want all my programs called the same thing.
I basically can't remember how I did the setup and can't find it anywhere on the internet.
Any help will be greatly appreciated
I found the link again:
http://www.python-exemplary.com/index_en.php?inhalt_links=navigation_en.inc.php&inhalt_mitte=raspi/en/installation.inc.php
Also my permissions for the new file were incorrect as Geany sends the file to /home/pi/scripts and I log in as root and not the pi user.
My intention is to achieve the following scenario:
A Windows or Linux user gives the command to print a document (using Ctrl+P) and views a dummy printer (virtual printer) in the list of available printers
The user selects the printer and gives the print command
Instead of actually printing, the dummy printer automatically sends the file, along with the selected paper size, format and so on, to a python script as input [optionally after converting it to PDF].
The Python script uploads the file to the cloud or some remote storage from where it can be retrieved and printed later on a physical printer when required.
I have already referred the answer to a similar existing question on StackOverflow and looked up CUPS and CUPS-PDF. CUPS_PDF is a virtual printer so that satisfies one criteria for me, but it doesn't let me handle the files sent for printing. I could monitor the directory in which the converted PDFs are placed and call the python script every time the directory changes, but that is far from an ideal solution.
I tried creating something similar in Windows by using win32 API in the form of a FILE printer, but again it doesn't let me handle the file to be printed.
I have also stumbled across Tea4CUPS which is kind of a programmable backend for the CUPS printer, but I am not really sure how to leverage that. Another alternative I encountered was to write a Virtual printer driver using Windows Driver Kit (WDK), but that seems overly complicated especially given the fact that I need the Virtual Printer to just redirect the file to be printed to my python script.
How can I achieve my desired scenario? Though I have Python experience, I have never worked on Virtual printers before this.
Use RedMon. It is an open-source windows printer port that simply redirects all printer output to a specific program (such as a python script).
The following procedure is valid for up to windows 10 released 2015:
Download and install the RedMon software using the installer.
Under devices and printers, run the "Add Printer" wizard as an administrator (or use win32 API)
Add the printer using a postscript driver (I personally prefer installing the Xerox Global Print Driver PS, but other PS drivers are already installed) and create a new "Redirected Port."
You can configure the options under the "Configure Port" to direct the output to your script.
I'm trying to make my python script run upon startup but I get the error message windowserror access denied, but I should be able to make programs start upon boot because teamviewer ( a third-party program I downloaded ) runs every time I restart my computer so I know that I should be able to make my program run at startup (I might be doing something different though, so if you could shed some light on what teamviewer is doing differently to get its script to run at startup that would be helpful).
Here is my script
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run')
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')
Any input is appreciated.
import webbrowser
webbrowser.open('www.youtube.com')
Get rid of all of that _winreg stuff. Instead, you (assuming double-clicking on a py file opens the console) should simply place it in your startup folder (C:\Users\yourusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup on Windows 7, and C:\Documents and Settings\yourusername\Start Menu\Programs\Startup in XP). This works because Windows tries to open all files in the startup folder, and if Python opens PYs by default, Windows will open the Python console. Try restarting, that should work.
Baboon:
I am a little late posting, but you seem to have left off the sam at the end of your code here.
When you open a key you need to add the user rights, if you do not _winreg defaults to "READ":
Here is a snippet from the python site
http://docs.python.org/2/library/_winreg.html#access-rights
sam is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. See Access Rights for other allowed values.
Here is the code corrected:
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run',_winreg.KEY_SET_VALUE)
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')