vbs提示没有在该机执行windows脚本宿主的权限。请与系统管理员联系

2022-07-30,,,

最近在项目中使用vbs来实现图片的批量删除和批量导入功能,但不知道为什么,只要在我机器上一运行vbs文件就提示“没有在该机执行windows脚本宿主的权限。请与系统管理员联系。”的错误。下面贴出本人的解决方法,并附上图片批量导入及批量删除的vbs代码。

如果只是因为权限问题可以查看这篇文章:

1、检查系统是否禁止使用了脚本运行,即打开“internet选项”的“安全”选项卡里“自定义级别”,看看“activex空件及服务”禁用的选项。
2、运行 regsvr32 scrrun.dll,即打开运行输入cmd,输入regsvr32 scrrun.dll,再回车。
3、最关键的一步,即看看注册表里的这个位置hkey_local_machine\software\microsoft\windows script host\settings在右边的窗口中是不是有个名为 enabled的dword键值,有的话把它删除或者把值该为 1 即可。
4、重新运行vbs文件即将正常。

vbs批量导入图片功能

'****************** 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,sfilepath,simgfile,xml
  dim ados,fso,f,oshell,serrfile,ssucfile,ierr,isuc
  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")
  
  sfilepath=wscript.scriptfullname
  sfilepath=left(sfilepath,len(sfilepath)-len(wscript.scriptname))  
ssql="select rybh, photo from tp_zpxx where (rybh in (select distinct rybh from tp_bmkm where (kszqbh = 18) and (jfbz = 1)))"
  sfzrs.open ssql,conn,adopenforwardonly 
  isuc=sfzrs.recordcount 
  
  'get sfzh from database and import images
  while not sfzrs.eof 
    simgfile= sfilepath & sfzrs("rybh") & ".jpg"  
    ados.open     
    ados.write (sfzrs("photo").getchunk(4500000))    
    ados.savetofile simgfile,1     
    sfzrs.movenext     
    ados.close 
  wend 
  
  sfzrs.close 
  conn.close 
  
  'release object
  set rs=nothing:set sfzrs=nothing:set conn=nothing:set ados=nothing
  
  msgbox isuc & "张照片导出成功",64 ,"照片导出"
    
  

  '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 "数据库联接失败",16 ,"照片导出"
    exit function
  end if
end function

vbs批量删除图片功能

'****************** 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  'isuc 文件总数
  dim picpath,physicpath,delcount '删除文件数
  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删除照片小程序" '物理路径    
    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 "共需要删除" & isuc & "张照片,其中" & delcount & "张照片删除成功," &isuc-delcount & "张照片未找到!",64 ,"照片删除"
    
  

  '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 "数据库联接失败",16 ,"照片删除"
    exit function
  end if
end function

到此这篇关于vbs提示没有在该机执行windows脚本宿主的权限。请与系统管理员联系的文章就介绍到这了,更多相关windows脚本宿主的权限内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《vbs提示没有在该机执行windows脚本宿主的权限。请与系统管理员联系.doc》

下载本文的Word格式文档,以方便收藏与打印。