Recent

Author Topic: Running secretly a Windows command lines  (Read 1212 times)

Saylo_49

  • New Member
  • *
  • Posts: 43
Running secretly a Windows command lines
« on: June 19, 2019, 06:37:50 pm »
Hello
I am working on a project that run secretly a windows app (like the xcopy.exe)
the output project binary must be launched and hiden on the windows startup
and on every peripheral insert (CD. Flash drive. external hdd. phone. memory card) the binary must execute a commands like :
Code: Pascal  [Select][+][-]
  1. xcopy "d:/" "c:/backuped/name-datetime"
  2. xcopy "e:/" "c ....
  3. xcopy "f:/"  ....
  4. and so on
  5.  
basically it will work with TProcess but i have no hint how to set the launch on system startup and the run on peripherics insert
please : help
Lazarus 2.0.2 - FPC 3.0.4 - Win32

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Running secretly a Windows command lines
« Reply #1 on: June 19, 2019, 06:43:02 pm »
Use autoexec.bat, maybe?

Or put your program binary's name in windows registry:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
or
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]

Secretly? ... hmmm ... it sounds you're planning to do something evil.  >:D

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Running secretly a Windows command lines
« Reply #2 on: June 19, 2019, 06:50:31 pm »
For further investigation (on your part--I don't have the smallest idea how it's done :)): what you're probably looking for is running your application as a service. The MSDN should have tons of docs on how to do that.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Running secretly a Windows command lines
« Reply #3 on: June 19, 2019, 07:49:48 pm »
on every peripheral insert (CD. Flash drive. external hdd. phone. memory card) the binary must execute a commands like :
Code: Pascal  [Select][+][-]
  1. xcopy "d:/" "c:/backuped/name-datetime"
  2. xcopy "e:/" "c ....
  3. xcopy "f:/"  ....
  4. and so on

Why are you using command-line apps to accomplish this, instead of using platform APIs directly in your code?  Look at the Win32 GetLogicalDriveStrings(), CopyFile(), SHFileOperation(), and IFileOperation APIs.

basically it will work with TProcess but i have no hint how to set the launch on system startup and the run on peripherics insert

For system startup, place a link to your app in one of the following Registry keys:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Or, place a shortcut to your app in the "Startup" folder of the user's Start Menu.

Or, design your project to run as a background service instead of an app, and set the service's start type to auto-start.

Either way, to detect when peripherals are inserted, you need to leave your program running and have it call the Win32 RegisterDeviceNotification() API to ask Windows to send WM_DEVICECHANGE messages to your app whenever devices are added to, or removed from, the system.
« Last Edit: June 19, 2019, 07:51:29 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Running secretly a Windows command lines
« Reply #4 on: June 19, 2019, 10:37:03 pm »
Quote
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Yeah... people "like" this very much !!!
But I guess your boss love this kind of observation-spy-software ...  :P
That's why intelligent people like to use AUTO RUNS ...  :D


Quote
Secretly? ... hmmm ... it sounds you're planning to do something evil.  >:D
:)  Heaven is lost forever after that ...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Running secretly a Windows command lines
« Reply #5 on: June 19, 2019, 10:55:10 pm »
What I say is this,,,

 "What you can not put in your own code to make it, should not be allowed to use External apps"

 Simply put, if you can't do it in your own code then just don't do it..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018