Im hoping i could have a push in the right direction for an issue I'm having. Im not even sure it is possible.
Idea:
Id like to have a batch file that runs on logon to check the logon type that is shown in the event viewer.
The ultimate goal is to allow logon with a keyboard at the station - password entered > logon type checked from event viewer (logon type 2)> if logon type 2 check to see if a USB with a certain serial is connected> if yes allow >if no lock PC right away.
issues:
I have no idea and have not found a way to get the logon type from the event viewer, It will only have to check the newest record.
i have the file that checks for the serial and if not EQU locks PC. its the event viewer I'm not sure on.
Im looking for this in a batch file. or Powershell (if this can be run at logon, i have never used this before)
Thanks for any and all help!!
Related
I have an Access VBA macro that generates a report, saves it in .pdf and then sends it by e-mail using CDO. Everything works fine if I run it manually or if I set it to be run on Task Scheduler with the security option "Run only when user is logged on". However, if I set the option to "Run whether user is logged on or not" (even with the option "Run with highest privileges") the program crashes on the second line of:
strFileFullPath = CurrentProject.Path & "\Test Report.pdf"
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFileFullPath
with the error
Microsoft Access can't save the output data to the file you've
selected.
I am pretty sure that this happens because the macro runs with other user in the background. I have been searching for a solution but all I have found is that it is not possible and that I should change for other printing methods, such as PDF Creator (which brings a lot of other issues).
I am using Access 2016 in Windows Server 2012 R2 Standard.
It sounds crazy, but after a few days with no results, I managed to solve my problem just by creating these two empty folders:
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
All the credits to Faye's comment on the bottom of this page: https://blogs.technet.microsoft.com/askperf/2015/02/18/help-my-scheduled-task-does-not-run/
Although the comment regards Excel, it solved my issue on Access. It seems that is related with Office having trouble with running some processes (in my case, a pdf generation) in non-interactive mode (which is the mode that Task Scheduler runs when "Run whether user is logged on or not" is checked).
Have a question on how to set the default printer for NEW users via powershell.
I have seen many posts about setting the default printer via the wmi method. This seems to work only for the currently logged in user that is running it. This will not work for other users that may have already logged in. I can set the default printer for user sid already in the profile list in the registry via HKU:\<SID>\Software\Microsoft\Windows NT\CurrentVersion\Windows key. I set the device string to the printer name and port, isMRUEstablished i set to 0 and legacydefaultprintermode i set to 1 to prevent windows from setting the last used printer as default. This seems to work for any users that have already logged on. Issue is i cant seem to find a way to set it system wide. If install the printer and set it up before the user gets the machine and logs in for the first time it wont be set for them. I have tried making the above mentioned registry changes to the .defualt user registry hive but when a new person logs into that machine they have something like webex document print set to the default or onenote printer or something else. Is there any other way to set via powershell so it will apply to a new user that logs on?
You have to load the hive from the default profile found in c:\users\default and called ntuser.dat.
After loading this hive make the reg setting as needed. Then unload the hive. Now anyone who logs in to the system for the first time will get those settings, whatever they are, by default. The .Default in the registry is what runs when the system is at login but not yet logged in so no effect for printer settings.
How to synchronize system date/time with the date/time on workstation in Windows 7? I am trying to use ADO.Net from devArt to connect to Oracle DB from Windows CE (Compact Framework). I want to use 30 days trial to test it before I buy it.
I am getting this error:
Sorry, your trial period has expired.
Support:
The possible reason may be that the system date/time of the device is
not synchronized with the date/time on your workstation; hence, the
issue can be resolved by setting the same date/time as set on the
workstation.
Please refer to http://windowstipoftheday.blogspot.cz/2010/03/windows-7-automatically-syncronzing.html
FTA:
In the Start menu search field type "Date and Time" and press Enter, this should be bring the Date and Time control panel
In the Date and Time dialog box, click the Internet Time tab.
Press the Change Settings button. Press the Continue button in the User Account Control dialog box (if it displays).
In the Internet Time Settings dialog, click the Server drop-down arrow and select another time server. The default is time.windows.com, try using time.nist.gov and see it works for you.
Press the Update now button to update your computer's clock, and test your computer's
Press the OK buttons close the dialog boxes.
For users with domain accounts, try using this command line command: w32tm /config /syncfromflags:MANUAL /manualpeerlist:time.nist.gov w32tm /config /update (thanks to #user6852928 for this).
How can I create a program that controls my computer based on commands which I have entered ahead of time.
For example:
My application should at 6pm enter facebook, enter my user credentials to log me in, and then leave a comment in the comment field which I have entered at 1PM.
Told means commend that I stored in this software.
My background is c++ and I realize programming philosophy since I program in machine language-I'm electrical engineer.
Thanks
Is this just for your own personal usage?
If so, I would advise not actually trying to develop an application yourself for this but instead use a Macro program. About 8 years ago when I was extremeley inexperienced at programming or doing anything, I used some macro programs to create bots in games, so doing something as trivial as logging you in would be simple.
Just have it..
Launch C:/Program Files/Mozilla/Firefox.exe (or something similar)
Press F6
Type: "http://www.facebook.com"
Press ENTER
Check pixel at local XXX x YYY to see if you are already logged in, in which case you don't need to enter your username and password
If you are not logged in, move mouse to coords XXX and left click.
Type username
Repeat for password.
Press ENTER
Navigate to profile.
Check the time on your system. If time is not 1PM, wait one minute and try again.
Repeat above.
Time is now 1PM so post your message.
End macro.
You could make that using a program like Macro Express within about 10 minutes. It also has a Capture editor, so that you can record your own macro and then edit it as you require.
http://www.macros.com/
This answer obviously assumes it is for personal usage.
I am looking for an inverse version of "RunOnceEx".
RunOnceEx does run some program, before the user's shell(desktop&taskbar) start. The login progress will not continue before the runonceex complete.
I want to do exact the same but on user logout.
When she/he logout, all running program shutdown, leaving shell(desktop&taskbar), then ""I wish my program will be execute this moment"", finally logout.
I think it is possible because the "mobsync.exe" is doing that. But I cannot find where and how to do it.
Warning, as said here, gpedit.msc will allow you to configure a logoff script for all users.
If you need that script only for one user, you need to declare it directly in the registry, both in HKCU and HKLM.
To run this only for the current user, you can use WMI to get an information when a shutdown/logout occurs.
Either you write a small C# (or any other language that can use WMI) application or vbs script to listen on the Win32_ComputerShutdownEvent WMI event.
An example C# app can be found here in this question: Get Log off event from system
found in the first result on google for me
To execute a program you can create a script to run it and use group policy to enforce it.
In Group Policy Editor navigate to User Configuration-->Windows Settings-->Scripts (Logon/Logoff)
more information here
If you want a running program to execute code on logoff, then you should hook the WM_QUERYENDSESSION message and look for an lParam value of ENDSESSION_LOGOFF (0x80000000).
It's important to test for this lParam value because the other ones indicate a "forced close" - i.e. your process may be killed before your code is even allowed to run. In fact, most shutdown/session-end messages are only intended to give you an opportunity to run last-minute cleanup code and aren't that safe to respond to with long-running actions; but this particular combination should be OK.
Note: I've never tried to actually run a separate process in response to the WM_QUERYENDSESSION message. It's possible that the window manager will disallow this, like it does during shutdown. Try it and see, I guess.
If you're in a .NET environment (you didn't specify), a quicker way is to add an event handler to the Microsoft.Win32.SystemEvents.SessionEnding event.
What you need is an implementation of GINA. You can run your custom commands in WlxIsLogoffOk function, which gets called when the user initiates a logoff
Once you create the proper GINA dll you can register it here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\#GinaDLL
Here is an implementation which may fit your needs (it provides a Logoff registry key where you could specify your command):
http://wwwthep.physik.uni-mainz.de/~frink/newgina_pre09/readme.html
As VonC and TFD already mentioned, the Group Policy Editor is just another way to manipulate the registry.
Just make with gpedit the changes (in Userconfig - Windows Settings - Scripts) you like and afterwards take a look in the registry at [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]
to find out how you can do that directly.
Also on my PC (hanging in a domain) is a hidden folder C:\WINDOWS\System32\GroupPolicy with subfolders for user and machine. Both having additional subfolders called Shutdown and Startup. Maybe you can also use these ones.
If you need something simple and working for a single (or any) user you can make a simple application in C++ or C# for example.
The simplest is having a C# in tray (by simply adding the tray component to the form) and register and event handler for the FormClosing event. It'd look like this:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.UserClosing)
{
// It's not the user closing the application,
// Let's do whatever you want here, for example starting a process
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";
notePad.Start();
}
}
So your application will be started with Windows or with the user. It'll wait (using a little bit of memory) and will do something when the system shuts down, or the user log off, etc (by checking "CloseReason" above).