Can i make a pc password lock system with batch file? - batch-file

I made an alphanumeric password checker using one-by-one char inputs via choice command.
I was to register it to start programs and lock my pc.
But it cannot catch CTRL-C terminating.
Piping echo N solution did not help me
because it recieves keyboard inputs.
How do i prevent users from typing CTRL-C?

Found this site: Dos Tips
The solution that I found to block CTRL+C aka Terminate Batch Y/N COMPLETELY.
No Fuss, No kidding, No Breaking Out. XOUT but that too can be disabled.
Briefly:
Code:
C:\PROFILES\ADMIN>REN "%COMSPEC:~0,-8%\CSRSS.EXE" !!!CSRSS.!!!
OOPS Windows File Protection. If WFP is enabled ask almighty Google about that.
Transpose the file names to undo. WARNING: This MAY also break your toaster. 8)
PRO: Disallow all programs from injecting code via CSRSS hooking.
CON: PROPERTIES from the System Menu of CMD Windows are disabled as well.
CON: Enemy Territory will certainly whine until dialog box is dismissed once.
ELSE This is bulletproof. I'm being extremely terse!
I would recommend reading the other page and some of the info on it before you run the script as it could be damaging. If you have a VM to test it on that would be best :)

Related

How do I make a C executable for Windows written on Linux not close the cmd as soon as it finishes running?

So, I've written a C executable on Linux for Windows using mingw32-gcc. It is a basic Input-Output program, you type an input and get an answer.
Problem is the cmd shuts down immediately, so the user can't see the output.
Assuming I cannot use Windows to edit the executable there, what should I change in my code/ what flags should I use when compiling it?
inb4:
the user is supposed to click and run it, so running it from cmd won't help.
adding getchar()/scanf() at the end of my code doesn't work, and it feels a bit like cheating.
SOLVED: so all I had to do was to actually add a getchar() after every scanf() and one more at the end of the code for the user input to close the cmd.
Waiting for input at the end is not cheating, but common practice. How else should program know for how long it should stay opened? Closing program by closing console window directly is more cheating than waiting for user input to finish.
You can for example prompt user to hit any key like Press any key to exit... or something similar.
If you want some specific delay, you can use Sleep() from windows.h instead of waiting for input.
See https://stackoverflow.com/a/3379146/3035795

How to enable logging in xterm

Is it possible to turn on logging feature by default in xterm?
Lets say for example, I have example program in c that give an output in xterm everytime i ran the program from default bash terminal in linux. And I want to save the output that shows in xterm into a file everytime the programs is run.
I'm using centos7_x86_64 fyi
Thanks.
In Windowmaker:
Hold down ctrl + left click in xterm window (on the terminal text), click on "log to file".
A cool thing to do is when you're coding, log the terminal, and then when you cat the Xterm log, you see coding in fast forward. If you wanted you could video it.
Note that there are also other menus in xterm, accessible using Ctrl+Left Click, Ctrl+Middle Click, Ctrl+Right Click.
Log file will be in the directory that you launched Xterm from, and will be in the format: Xterm.log.<hostname>.<date>.<time>.log.
This is a very good question, there's no reason to mark down a question like this.
It can be done in two ways:
Using script:
xterm -e script mylogfile -c "someCommand -i input_file -o output_file -f someArg"
Redirect to a file:
xterm -e 'someCommand --arguments 2>&1> /path/to/mylogfile'
I do essentially this with "terminal-window", mrxvt, "hcm" and "pypty".
terminal-window wraps mrxvt, just filling in some commandline options. mrxvt is a lightweight, multitabbed, nonunicode terminal emulator not dissimilar to xterm.
hcm is a GUI that makes it easy to run a shell (or other command) on a remote host. It can also start an mrxvt with remote ssh's without requiring the GUI if you prefer (using hcm-term).
pypty is a /usr/bin/script reimplementation that is written in Python. It is not significantly different from /usr/bin/script, except it gives a "dated files mode", that allows you to have one file per pseudo terminal per day. So if you leave a shell logged in overnight, you get one file per day - this tends to make it easier to find what you're looking for.
All this combines to give you pseudo terminal logging with great ease. Commands are run on remote hosts, but logged locally. Just start a "fancy terminal-window" (or use hcm-term), and everything you see on the screen plus control characters (but not nonechoed passwords) will be logged under ~/.hcm/logs/<year>/<month>/<day>/* .
Also, if you hit the shell button in the lower right of mrxvt, you get another ssh session into the same remote host, which is also logged locally (to a different file under ~/.hcm/logs/...). When I started making use of that feature, I had no idea how much I would grow to like it.
You can obtain them from http://stromberg.dnsalias.org/~strombrg/hcm/ There's a video there that shows how easy it is to set up and get started with.
BTW, fancy terminal-window sets up $PS0 or "trap DEBUG" to give you command start times and finish times. It's great for post mortems. It does this without replacing any of the usual bash startup files.
I wrote terminal-window, hcm and pypty, but I can't take credit for mrxvt. :)
HTH

AppleScript: "file is already open" but "file wasn't open"

Because of my slightly obsessive personality, I've been losing most of my productive time to a single little problem.
I recently switched from Mac OS X Tiger to Yosemite (yes, it's a fairly large leap). I didn't think AppleScript had changed that much, but I encountered a problem I don't remember having in the old days. I had the following code, but with a valid filepath:
set my_filepath to (* replace with string of POSIX filepath, because typing
colons was too much work *)
set my_file to open for access POSIX file my_filepath with write permission
The rest of the code had an error which I resolved fairly easily, but because the error stopped the script before the close access command, and of course AppleScript left the file reference open. So when I tried to run the script again, I was informed of a syntax error: the file is already open. This was to be expected.
I ran into a problem trying to close the reference: no matter what I did, I received an error message stating that the file wasn't open. I tried close access POSIX file (* filepath string again *), close access file (* whatever that AppleScript filepath format is called *), et cetera. Eventually I solved the problem by restarting my computer, but that's not exactly an elegant solution. If no other solution presents itself, then so be it; however, for intellectual and practical reasons, I am not satisfied with rebooting to close access. Does anyone have insights regarding this issue?
I suspect I've overlooked something glaringly obvious.
Edit: Wait, no, my switch wasn't directly from Tiger; I had an intermediate stage in Snow Leopard, but I didn't do much scripting then. I have no idea if this is relevant.
Agreed that restarting is probably the easiest solution. One other idea though is the unix utility "lsof" to get a list of all open files. It returns a rather large list so you can combine that with "grep" to filter it for you. So next time try this from the Terminal and see if you get a result...
lsof +fg | grep -i 'filename'
If you get a result you will get a process id (PID) and you could potentially kill/quit the process which is holding the file open, and thus close the file. I never tried it for this situation but it might work.
Have you ever had the Trash refuse to empty because it says a file is open? That's when I use this approach and it works most of the time. I actually made an application called What's Keeping Me (found here) to help people with this one problem and it uses this code as the basis for the app. Maybe it will work in this situation too.
Good luck.
When I've had this problem, it's generally sufficient to quit the Script editor and reopen it; a full restart of the machine is likely excessive. If you're running this from the Script Menu rather than Script Editor, you might try turning off the Script Menu (from Script Editor) and turning it back on again. The point is that files are held by processes, and if you quit the process it should release any lingering files pointers.
I've gotten into the habit, when I use open for access, of using try blocks to catch file errors. e.g.:
set filepath to "/some/posix/path"
try
set fp to open for access filepath
on error errstr number errnom
try
close access filepath
set fp to open for access filepath
on error errstr number errnom
display dialog errnum & ": " & errstr
end try
end try
This will try to open the file, try to close it and reopen it if it encounters and error, and report the error if it runs into more problems.
An alternative (and what I usually do) is that you can also comment out the open for access line and just add in a close access my_file to fix it.

C - running program accept input

This is a very beginner-level question in C.
Don't know where to start looking/searching.
So, if I have a program continuously running in C, what is the best way to accept input through the command line into the program?
EX, mysql is already running, but you can process a command call
mysql SELECT * FROM *
Do I need a different program to write to file/stdin?enter code here
Clarification:
So, mysql seems to be able to take in commands while it is already running... is that possible in C?
Goal:
I have some hooks into open gl es, and I want to run a continuous draw loop in the background, while having the ability to call commands such as
glhookprogram make "object1" model "triangle" program "default"
glhookprogram attr "object1" position "1.0, 1.0, 0.0" scale "2.0" rotation "45, 0, 0"
this way, I can have a node server run hw-accelerated animations in javascript on the rpi.
Looks like this is what you need (and I'm sorry - I won't be going into too much details as there are plenty of sources on the Web about that):
A "server" - that would be your background process that stays running in memory and can accept and process commands (requests)
A "client" - a (short-running?) process that can accept commands from user (GUI, command-line. Network? Other process?) and send requests to your "server"
This is not a trivial task for a beginner. I would suggest googling for "server-client" and for "inter-process communications" first and go from there.
The range of options to "accept input" into your server includes (but is not limited to) the following:
(Windows) messages
Shared memory and a command queue (producer-consumer)
Shared file (just listing it here for completeness, I'd advise against this particular one for your case)
Named pipes
Sockets (thanks for reminding me of those in the comments, can't believe I missed that!)

How to read from keyboard when stdin is set to a file in C

I think this is simple, but not for me obviously!
I have a console-application. I need to read input from the keyboard, but stdin has been redirected to a file. So how do I create a FILE-Handle that points at the keyboard-stream which i can use with fgets etc.?
I found out that ttyname(0) seems to be what i look for in a POSIX-environment, which I don't have here. I'm in a Windows-system with standard Visual Studio compiler.
Any ideas? Thank you in advance.
There's no easy/portable way to tell if a keyboard exists (your application may be being run from a terminal emulator from a serial port, a telnet session or anything else). If a keyboard actually does exist (including a picture of a keyboard on a touch screen), then you can't really tell how many layers of software the keystrokes need to pass through before they get to your application (e.g. keystrokes might go from a keyboard driver to an input method editor to a GUI to a shell to your application). This means that attempting to get keystrokes directly from a keyboard driver or something is a bad idea that will fail in almost all cases.
The best way to solve your problem is to find out which series of design failures led to STDIN being redirected in the first place.
For example; maybe the application should've had a command line option to read some data from a file; so that the application can get some data from the file and some from STDIN (and get all data from STDIN if the command line option isn't present).
Pulling from the dim dark days of DOS programming here: try opening "CON:" (Console), a reserved word. Hopefully it will open the same way in Windows. The colon may or may not be required. Both "dir >con:" and "dir >con" still work in command prompt.
Also, be sure to use something from the setbuf() family on the output handle to avoid buffering... it's not supposed to buffer terminal I/O, but it never hurts to be sure.
Again, not sure, but I suspect opening separate FILE *conin, *conout for output and one for input may help if you seem to have troubles with one handle doing both input and output.

Resources