понеділок, 3 грудня 2018 р.

Windows shutdown in command line

The most common ways to use the shutdown command are:
  • shutdown -s — Shuts down.
  • shutdown -r — Restarts.
  • shutdown -l — Logs off.
  • shutdown -h — Hibernates.
    Note: There is a common pitfall wherein users think -h means "help" (which it does for every other command-line program... except shutdown.exe, where it means "hibernate"). They then run shutdown -h and accidentally turn off their computers. Watch out for that.
  • shutdown -i — "Interactive mode". Instead of performing an action, it displays a GUI dialog.
  • shutdown -a — Aborts a previous shutdown command.
The commands above can be combined with these additional options:
  • -f — Forces programs to exit. Prevents the shutdown process from getting stuck.
  • -t <seconds> — Sets the time until shutdown. Use -t 0 to shutdown immediately.
  • -c <message> — Adds a shutdown message. The message will end up in the Event Log.
  • -y — Forces a "yes" answer to all shutdown queries.
    Note: This option is not documented in any official documentation. It was discovered by these StackOverflow users.

четвер, 29 листопада 2018 р.

Delphi warning "Unsafe type 'PChar'"

There is not only way to define it in the Delphi IDE settings by excluding raise of this type of warning.

var sa, sb: String; ca, cb: array[0..1023] of Char; … StrPCopy(ca, sa); StrPCopy(cb, sb);
  CopyFile(ca, cb, False); ...


Even better solution is to create class function:

type TCharArray = array[0..1023] of Char; ... class function TGeneralLibrary.StrToPChar(AText: String): TCharArray;
class function TGeneralLibrary.StrToPChar(AText: String): TCharArray; var cArray: TCharArray; begin StrPCopy(cArray, AText); Result := cArray; end; ...

неділя, 25 листопада 2018 р.

Kill service in command line

You don't have to restart your machine. Start cmd or PowerShell in elevated mode.
sc.exe queryex <SERVICE_NAME>
Then you'll get some info. A PID number will show.
taskkill /pid <SERVICE_PID> /f
Where /f is to force stop.
Now you can install or launch your service.

середа, 17 жовтня 2018 р.

SQL Server Cannot drop database because it is currently in use…

A session connected to another database might have an open transaction that also affects your database - sp_who2 will only show one database. It could also be something as simple as Object Explorer or Object Explorer Details open in SSMS, which again would only show one database in sp_who2.
Don't bother trying to find the session that is responsible; just kill them all with one statement (and make sure it isn't your copy of SSMS that is connected, e.g. another query window, Object Explorer, etc.):
USE master;
GO
ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
--Now you will be able to drop it, and do that using DDL, not the UI:
DROP DATABASE dbname;

І це працює, перевірено ;)