Counting computer login times for the week - windows

I am probably asking this question in the wrong place (Maybe I should go to an OS forum) - but I still want to know this.
I am using a windows- 7 machine for my work. I log in everyday, do some work and then log off. I take a few short breaks in between when I Lock (Windows+L) my laptop.
I have to account for the number of hours worked by the end of the week which means the time for which I was logged in to this machine.
The problem is that I do complete all the work that is assigned to me, but I forget to keep track of the exact hours I was logged into this machine. I may have logged in at 5 am in the morning and then logged off at 3 in the afternoon- and I dont have any manual logs of my time.
Is there someplace where windows keep a weekly track of
Say per day:
"The Latest log-off time - The Earliest Log in time" into that system for a particular day. I only need these logs for a week.
any heads up would be appreciated. Thanks

I have tried to solve this problem for years, but only recently found a solution that:
May be implemented without administrative privileges
Does not require extra software
Kudos to Guiding Tech for providing the solution shown below. Change the suggested folder and filenames as you desire, but adjust the batch file code and Task Scheduler commands accordingly.
Part One: Create the script
Create the folder where you would like the script and text log file of login and lock/logoff to reside. For this example, I will presume the desired folder is "C:!Scripts\Login\"
Create a new text file in the folder and name it login.bat. A quick way to do this is to right-click a blank space in the folder view, and select New > Text Document, then name it login.bat.
Open the text file and copy and paste in the following code:
echo off
set datecode=%date:~-4%-%date:~7,2%-%date:~4,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
if "%1"=="i" echo %datecode% - Logged in >> C:\!Scripts\Login\login.txt
if "%1"=="o" echo %datecode% - Locked computer >> C:\!Scripts\Login\login.txt
Save the new batch file
Part Two: Create the login task
Open Task Scheduler. Press the Windows key, and then type "Task Scheduler" and click on the application that appears with that name. Alternatively, use Start > Run (Win + R), type taskschd.msc and press Enter.
Select Create Task... from the actions on the right hand side
Enter a task name like "Log the login date and time"
Click on the Triggers tab and add a new trigger. Select:
Begin the task: At log on
Specific user: This should be your Windows account name.
Click OK to add the trigger.
Add another trigger, except this time select Begin the task: On workstation unlock. Click OK to add the trigger.
Click on the Actions tab. Add a new action and point it to your login script with the argument i.
Click OK to add the action.
7. (Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power. Click on OK to create the task.
Part Three: Create the lock task
In Task Scheduler, select Create Task… from the actions on the right hand side.
Enter a task name like Log the lock date and time.
Click on the Triggers tab and add a new trigger. Select:
Begin the task: On workstation lock
Specific user: This should be your Windows account
Click OK to add the trigger.
Click on the Actions tab. Add a new action and point it to your login script with the argument o.
Click OK to add the action.
(Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power. Click on OK to create the task.
Part Four: Testing that everything is working as expected
Your work is now complete. You just need to test that everything is working as expected. Just lock your computer by hitting WIN+L and log back in. If you followed the instructions properly, you should now have a file called login.txt in the same folder as your script. This file should contain a log of each time you log in and out of your computer.

You can use the event log to check when you logged in and logged put (or locked the PC for that matter) but you would have to do that by hand.. You could write a program to do that but that would be hard.
BTW: You will need to enable a group policy or something to enable login events. Have a look here

Related

Windows Task Scheduler & Administrator user

I have to run automatically a batch file once a week to update a file.
To do so I have created a task with Windows Task Scheduler on the company Server with the following options:
Security Options: user me, run only when user is logged in, Configure for Windows Server 2012
Trigger: every Monday at 11.00am
Action: start a program (the path to the bat file with quote)
This configuration works fine. However I wish the update to happen even if I am not here.
So I tried to change to Security Options to:
User: administrator (with batch job rights)
Run whether user is logged on or not
Run with Highest privileges
Trigger and action are unchanged.
I have also entered the admin password when saving the task.
On the Task History the action and task are completed, but the bat file is not run and there is no update happening on my file.
The Last Run Result display:
Incorrect function (0x80070001).
Looking at other posts I have tried different combination:
Run with Highest privileges: ticked or not
The path to the bat file with or without quote
Try to add the path without quote in Start in (optional)
None of these worked. Any idea?
The code is working fine when activated manually. I am not sure what you mean by the command that start the batch.
In the Scheduler it is on the Action tab. The action is start a program and the details is the path to the file ...run.bat
When launch manually I right click on the file and select run as administrator.
Thank you in advance for your help.
Sylvie
had the same problem with a RScript.exe with batch .R file. Runs perfect with main user, also in command line, but when setting the 'run with different user account' it fails.
What I did: added the ScriptUser (an anonymous user that will work forever when I have left the building) to the group Power Users. (Ok, I don't think you are allowed to set it to Administrator). But local\powerusers did it for me. The strange 'Incorrect function' without any details is solved now.
V
I have been having similar issues with a new scheduled task I was setting up. I could run the .exe no problem by itself by clicking on it, but when task scheduler would run it, the app would execute instantly and return a success, but did not actually execute. For us, the solution was to include the Start in folder on the Action tab where you specify the application location. Leaving this value blank will default to the root directory where the most things do not have permission to run.
Task Scheduler Action Settings:

login to remote windows machine through batch file from another windows machine

My remote windows server restarts at fixed time , i need to login daily after restart , since i have scheduled few tasks in the server and they run only when loged in , please help me to automate the login process , can we do this through batch files ? like we can do the restart
If you have Windows 2008 or above you can use Task Scheduler. Open Control Panel and run the Task Scheduler. Right click on Action menu and run Create Task. Create the task as usual select "Run whether user is logged on or not" and (if need) select the "Run with hightest privileges" checkbox. Then go to Triggers tab and click the "New" button. There are many conditions for run this task. Select "At stratup" and click OK. Then in the Action tab select the "New" button. There select in Action "Start a program". Click Browse button and select your script or batch file. Click OK. Repeat as necessary. Click OK again and create the new Task.
Good luck.

Windows Server 2008 R2 scheduler ignores "hidden" setting

I have the following problem: I've created scheduled jobs that are only containing calls to a cmd and have parameters that contain things like project name etc.
I know about the fact that you have to set it to "Run only when user is logged on" if you want to see the window (cmd in this case) and also have to uncheck "hidden".
Until a week or two ago that worked fine, the box was showing up. Now the exact same job does no longer show the dos box. I suspect a windows update but I couldn't find anything useful in the update history of the server.
Do you guys have any idea what it might be? I tried switching the settings between the two "run as" options, tried setting it to hidden, tried switching "configure for" around...
The jobs run ok most of the time, the output is generated in most cases but if things go wrong I want to see the shell and not have to pipe everything to a .txt :/
I tried looking on google etc for a solution but only found other problems or the "my tasks run hidden if I choose run whether user is logged on or not" solutions.
Any ideas or hints? Anything would be really appreciated!
As you use scheduler to automate running of some rutine task, what's the point of manually checking/controlling it's execution? It is sort of negates benefit of automation and should be done through some basic logging (you can built in in your task scripts or whatever it is) and even viewer where you can check whether your tasks was run successfully.
Why it is required to you to see this window? Are you really need it?
If you state that it used to work OK then check logs does your tasks run successfully all the tine but hidden from you or it's something else?
Try to re-create / create new task & check whether it is not run hidden with settings you use.
From your description your scheduled task indeed configured so that it should be visible, namely:
- It is scheduled under your current logon account.
- It is configured to Run only when user is logged on.
These 2 conditions required for task to be visible.
The Hidden checkbox in the Windows Task Scheduler has nothing to do with how the scheduled program is displayed (in fact, there are no display options for scheduled tasks like there are with shortcuts). The Hidden checkbox controls whether or not the task is displayed in the Task Scheduler. If you set check it, then Task Scheduler will not display it unless the View Hidden Tasks option in the View menu is selected. You should still see the program window when it runs even if it is checked.
You did not indicate what changes you had made to the task between the time it worked and when it stopped, but one change that would prevent the window from being shown is if you had changed the account that runs it to the SYSTEM account. That is a trick that people use to hide the window (which is not a good solution, especially since there are much safer options), so if you had changed that, then you would not see it.
(The OP may have already fixed this by now), but if anyone else has the same problem, check the user account. If the task is not too complicated, you could do as Mikhail suggested and re-create the task from scratch.

Permission denied when trying to import a CSV file from PGAdmin

I'm using PGAdmin 1.14.3.
When I try to execute an import command:
COPY grad(country_code, postal_code, place_name, admin_name1, admin_code1, admin_name2, admin_code2, admin_name3, admin_code3, latitude, longitude, accuracy)
FROM 'C:\\Users\\denis\\Desktop\\BP2Project\\USA\\US.txt';
I get a
ERROR: could not open file
"C:\Users\denis\Desktop\BP2Project\USA\US.txt" for reading:
Permission denied SQL state: 42501
I did look up other similar questions and none of them solved my issue.
I logged in as user "postgres" who is the superuser. I don't see why I'm missing permissions. I'm on Windows 7.
The permissions article mentioned in the answer by Houari and Flimzy is a good reference material, but a direct answer (the quick fix I used) is:
Right click the folder containing the data file(s) that permission was denied to and then click Properties.
In the Folder's Properties window, select the Security tab.
Click the Edit button.
In the "Permissions for the folder" window that opened, click the Add... button.
Type Everyone into the "Enter the object names to select" text area box.
Click OK and the window will close.
Verify that the default Read & Execute permissions were set to Allow via the check checkbox in the previous window.
As JLB notes, Write permission is needed if dumping from PostgreSQL, opposed to copying into it.
Click OK and the window will close.
Click the Apply button in the Folder Properties window.
Now you can run the SQL COPY statement that needs to access those files.
Once done, return to the Folder's Properties window.
Click the Edit button.
Select the Everyone entry in the "Group or user names:" field.
Click the Remove button.
Click OK on the remaining open windows.
The permissions have now been returned to what they were.
The user Postgres must have read access on the file from which you are about to copy.
Look at this article to see how to modify files' security access on Windows.
Ok, this is how got COPY command working,to export a table to CSV, step by step.
Pls note that I am using pgAdmin 111.
Create the target folder you want to export a table to. E.g C:\myExports
Set a read/write permission on this folder following the steps below :
Right click the folder containing the data file(s) that permission was denied >to and then click Properties.
In the Folder's Properties window, select the Security tab.
Click the Edit button.
In the "Permissions for the folder" window that opened, click the Add... button.
Type Everyone into the "Enter the object names to select" text area box.
Click OK and the window will close.
Verify that the default Read & Execute permissions were set to Allow via the >check checkbox in the previous window.
Click OK and the window will close.
Click the Apply button in the Folder Properties window.
This is the tricky part, inside myExports folder create a blank CSV file with your desired name.E.g employee.csv
Then run the Copy command like this :
copy employee to 'C:\myExports\employee.csv' delimiter ',' csv;
employee is the table name in this example..
Hope this helps.
If you don't want to give permissions to Everyone, you can add permissions to the account that started the service. In the Control Panel - Administrative Tools - Services, copy the account name in the 'Log On' tab. (On my system the account is called 'Network Service'.) Then share the folder with the CSV-file with this user as shown in the answer above.
To solve this problem you must give permission to the CSV file because that CSV file present in a COPY command are read directly by the server, but not client application. So to make this file accessible to a server we must give full read-write permission so that Postgresql user can read and write on that file.
Reference: article showing step by step procedure.
I just ran into this error and even after adding postgres to permissions on the file folder and the file itself, it still didn't work. So, I put the file in a public folder. On Windows this was the path: "C:\Users\Public\Documents\census.csv." It worked!
Responses to this problem on different threads go something like this
1. "Tell me exactly what command you used"
2. "Make sure you have right permissions"
3. "Just use /copy"
I just tried giving permissions to Everyone on the cvs file I am trying to copy from, and it is still giving me the permission denied error. I think this functionality is broken and has been broken for multiple consecutive releases over multiple consecutive versions of Windows.
for me and I've just spent some long hours on this.
I have a central db residing on a HP box running 14.04 postgresql-9.5 pgAdmin3 postgis-2.2, shares are made through a tweeked Samba share. My clients are using a mixture of windows 10.1, 7, 8.1 and I have one ubuntu 14.04 desktop.
I'm working with large tables updating records and normalising data and have built the routines around SQL copy statements from CSV files which were made from the core COPY public.table_1 TO (the share folder I'd set up in Samba https://www.youtube.com/watch?v=ndAYZ0DJ-U4) '/srv/samba/share/[filename].csv'
I can then update the database once the tables have been amended with COPY table_1 from '/srv/samba/share/test.csv' USING DELIMITERS ',' WITH NULL AS '' CSV HEADER; from any of my clients.
The key as far as I have been able to determine is that the clients doing the updating must be superusers, also everything must tie up in terms of users as there are 4 servers working together here Postgresql, Samba, UNIX and WINS
All of my users are registered on each of the servers with the same username and password homogeneity is the main factor.
I had tried for a long time moving things about and trying various naming conventions but in the end it was http://www.postgresql.org/message-id/CFF47E56EA077241B1FFF390344B5FC10ACB1C0C#webmail.begavalley.nsw.gov.au that sorted me out it was like a big switch clicking in. chown 777 on your shares and group management was an important learning curve but., the hours I've spent on this will reap rewards down the line... Loving Ubuntu loving life and loving the spirit of open source but that just might be sleep deprivation kicking in... IT WORKS
I am trying to execute SQL commands directly from a file in psql 14, and landed the same error.
The reason is that "postgres" user is different from the 'admin' or the main user of the operating-system. So, this main user denies "postgres" to access files from its file system.
Although there is a way to bypass it.
Windows lets any user access the files in 'C:\Users\Public' and Linux distros allow files in '/tmp' folder to do the same.
So, whatever files you are trying to access from postgres' terminal, keep the files in
'C:\Users\Public' for Windows
'/tmp' in Ubuntu
Read from the orginal source of this answer
use \copy command from psql instead with this config:
sudo psql -U postgres -d <your-db> -c "\copy <your-query-or-table> TO '<pat-to-save-file>' WITH (FORMAT CSV)"

Task Scheduler - Show me a message when I lock my computer

Here's what I need to happen:
When I leave the office for the day, I lock my computer. We're supposed to fill out our timecards before leaving. I always forget to do it. I want a message to be displayed when I attempt to lock my computer asking me if I've filled out my timecard.
Here's what I've done, and why it doesn't work:
I created a task under Task Scheduler with action = "Display a message" and trigger = "On workstation lock". The problem with this is the task doesn't run until the workstation is literally locked and I don't see the message until I log back in again, which is pointless.
How can I do this so immediately after I press Ctrl-Alt-Del, but before my computer actually locks the message is displayed?
Any help would be appreciated. Bonus points awarded for the following:
1) Display the message only if after say 3:00pm, as I lock my computer multiple times a day and I would get the message every time. The 3:00pm constraint would assume I'm leaving for the day and therefore, it should ask me if I've filled it out.
2) At the end of the message, display "Would you like to visit the timecard site?" and display 2 buttons, Yes and No. If I click yes, the locking of the workstation is cancelled and the timecard site opens up in my browser. If no is clicked, the workstation goes on to be locked.
Thanks.
You could pop your message up by calling MessageBox() with the MB_SERVICE_NOTIFICATION flag. That will cause the message box to be popped up on the console even if the logon screen is showing...
I doubt that this is possible. When you press CTRL+ALT+DEL Windows handles that key press and you can't get a look in.
What you could do would be to put a shortcut on you desktop that locked the computer, but only after having shown the message you so desire. I have a Lock Workstation shortcut on my desktop which is implemented with the following target:
C:\Windows\System32\rundll32.exe User32.dll,LockWorkStation
You could quite easily write your own script, or maybe even a small app. If the latter then you simply need to call the LockWorkStation function that is exported from user32.dll.
change the action to a program, run this program
msg username message
ie: msg patrick Please remember to do this.

Resources