Run bat file in Delphi

Source: Internet
Author: User

D Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Unit Map;

Interface

Uses
Winapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics,
Vcl.controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls;

Type
TForm1 =class(Tform)
Mmo1:tmemo;
Btn1:tbutton;
Edtusername:tedit;
Lbl1:tlabel;
Edtpassword:tedit;
Label1:tlabel;
Edtsharefolder:tedit;
Label2:tlabel;
Btn2:tbutton;
Procedure Btn1click (Sender:tobject);
Procedure Formclose (Sender:tobject; var action:tcloseaction);
Procedure Btn2click (Sender:tobject);
Private
{Private declarations}
Public
{Public declarations}
End

Var
Form1:tform1;

Implementation

{$R *.DFM}

Procedure Tform1.btn1click (Sender:tobject);
Var
Createbatfile:tstringlist; //Used to create a bat file
Batchfilepath:textfile; path to the//bat file
command:string; //Command to execute
begin
Createbatfile: =tstringlist.create; //Create a string file
Createbatfile.savetofile (' C:\Temp\MapScanDriver.bat '); //Create a bat file on the C:\Temp directory
Createbatfile.free;
AssignFile (Batchfilepath,' C:\Temp\MapScanDriver.bat ');
Rewrite (Batchfilepath); //Clear
CloseFile (Batchfilepath);
Command: =' net use H: '; //Construction commands
command: = command + Edtsharefolder.text +' ' " ';
Command: = command + Edtpassword.text +' "/user:" ';
Command: = command + Edtusername.text +' "';
Mmo1. Lines.add (Command); //Command Copy to Memo control

Mmo1. Lines.savetofile (' C:\Temp\MapScanDriver.bat '); The command line on the memo control is saved directly to the bat file
WinExec (' C:\Temp\MapScanDriver.bat ', SW_SHOWNORMAL); //execute command


End

Procedure Tform1.btn2click (Sender:tobject);
Begin
Mmo1. Lines.clear;
Edtusername.clear;
Edtpassword.clear;
Edtsharefolder.clear;
End

Procedure Tform1.formclose (Sender:tobject; var action:tcloseaction);
Begin
Mmo1. Lines.clear;
Mmo1. Lines.savetofile (' C:\Temp\MapScanDriver.bat '); //write empty to bat file
End

End.

Run bat file in Delphi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.