VBS prompts that you do not have permission to execute Windows Script Host on this machine. Please contact your system administrator

Time:2021-9-23

Recently, VBS has been used in the project to realize the functions of batch deletion and batch import of pictures, but I don’t know why. As soon as I run the VBS file on my machine, I will be prompted with the error “I don’t have the permission to execute Windows Script Host on this machine. Please contact the system administrator.”. The following post my solution, and attach the VBS code of batch import and batch deletion of pictures.

If it’s just a permission issue, you can view this article:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'****************** Const ****************
'---- CuRsorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
 
'---- LockTypeEnum Values ----
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3
Const adLockBatchOptimistic = 4
 
'---- CuRsorLocationEnum Values ----
Const adUseServer = 2
Const adUseClient = 3
 
'---- Custom Values ----
Const cuDSN = "test"
 
Const cuUsername = "sa"
Const cuPassword = ""
 
'*************** main sub ******************
 
Call ImageExport()
 
'*************** define function ***********
 
Function ImageExport()
  'on error resume next
  Dim sSQL,Rs,Conn,sfzRs,xml
  Dim Ados,fso,f,oShell,sErrFile,sSucFile,iErr,iSuc   ' Total isuc files
  Dim picpath, physicpath, delcount 'number of files deleted
  Set fso = CreateObject("Scripting.FileSystemObject")
  
    ' Create Stream Object
  set Ados=CreateObject("Adodb.Stream")
    Ados.Mode=3
    Ados.Type=1
 
  Set Conn=CreateObject ("adodb.Connection")
  Conn.CuRsorLocation =adUseClient
  Call Init_Connection(Conn)
  Set Rs=CreateObject ("adodb.recordset")
  Set sfzRs=CreateObject ("adodb.recordset"
  
  sSQL="select sPath,sFile from ScanFile"
  sfzRs.Open sSQL,Conn,adOpenForwardOnly
  iSuc=sfzRs.RecordCount
  
  'Get SFZH From DataBase and import images
  while not sfzRs.EOF
    PhysicPath="E: \ VBS delete photo applet" 'physical path
    Ados.Open  
    PicPath =PhysicPath & sfzRs("sPath") &"\" &  sfzRs("sFile")   
    If (fso.FileExists(PicPath)) Then
      fso.DeleteFile(PicPath) 
      DelCount=DelCount+1
    end if   
    sfzRs.MoveNext    
    Ados.Close
    if iSuc-DelCount=iSuc Then
      DelCount=0
    end if   
  wend
  
  sfzRs.Close
  Conn.Close
  
  'Release Object
  set Rs=nothing:set sfzRs=nothing:set Conn=nothing:set Ados=nothing:set fso=nothing
  
  msgbox "Total needs to be deleted" & iSuc & "Photos of" & DelCount & "Photos deleted successfully," &iSuc-DelCount & "Photo not found!",64 ,"Photo delete"
    
  
 
  'Quit
  WScript.Quit
  
End Function
 
Function Init_Connection(Conn)
  on error resume next 
ConnStr = "Provider=SQLOLEDB;Data Source=192.168.64.114;" & _
        "Initial Catalog=VoteInfo;User Id=sa;Password=123456;timeout=50"
  Conn.Open ConnStr 
 
  If Err.number Then   
    msgbox Database join failed,16 ,"Photo delete"
    exit function
  End If
End Function

This article about VBS suggests that you do not have permission to execute Windows Script Host on this machine. Please contact the system administrator. This is the end of the article. For more information about the permissions of Windows Script Host, please search the previous articles of developeppaper or continue to browse the relevant articles below. I hope you will support developeppaper in the future!

Recommended Today

Seven Python code review tools recommended

althoughPythonLanguage is one of the most flexible development languages at present, but developers often abuse its flexibility and even violate relevant standards. So PythoncodeThe following common quality problems often occur: Some unused modules have been imported Function is missing arguments in various calls The appropriate format indentation is missing Missing appropriate spaces before and after […]