winxp下用vbs寫的代碼編輯器
來源:易賢網(wǎng) 閱讀:1168 次 日期:2016-06-30 08:48:02
溫馨提示:易賢網(wǎng)小編為您整理了“winxp下用vbs寫的代碼編輯器”,方便廣大網(wǎng)友查閱!

幾天不能訪問的時(shí)候把硬盤上的東東復(fù)習(xí)了一遍,找出了這個(gè)東西出來,由于水平有限,而且對(duì)dhtml沒有什么研究,所以做得很是粗糙,貼上來是為了拋磚引玉,希望有高人能幫忙修改或拿出更優(yōu)秀的東東出來。

測(cè)試環(huán)境為windows xp 專業(yè)版 sp2,暫時(shí)發(fā)現(xiàn)代碼著色方面有bug,雖然已有解決方法,不過由于代碼量的原因(用記事本寫代碼真的很惱火),暫時(shí)未糾正,另外預(yù)計(jì)將來加入自動(dòng)完成等功能。

ps:利用vbs腳本+dhtml,主要功能由正則表達(dá)式+wmic來完成,代碼需保存為hta類型的文件,當(dāng)然也可以更改為純粹的vbs腳本,不過那樣效率低多了,而且代碼更復(fù)雜。

代碼如下:

<html>

<head>

<title>代碼編輯器</title>

<hta:application selection=no scroll=no contextmenu=no />

<script language=vbscript>

'*******************************************************************'

'腳本開始

'*******************************************************************'

set shell=createobject(wscript.shell)

set fso=createobject(scripting.filesystemobject)

'*******************************************************************'

'遍歷本地所有類型文件

'*******************************************************************'

sub optionadd(fext)

str = <select size=1 name=objoption onchange=testsub>

set objdatafiles = getobject(winmgmts: _

& {impersonationlevel=impersonate}!\\.\root\cimv2)

set colfiles = objdatafiles. _

execquery(select * from cim_datafile where extension = ' & fext & ')

for each objfile in colfiles

str = str & <option value= & objfile.name & > & _

objfile.name & </option>

next

str = <label>本地腳本文件:</label> & str & </select>

foroption.innerhtml = str

end sub

'*******************************************************************'

'顏色轉(zhuǎn)換

'*******************************************************************'

sub changecolor

if cxs.value = vbs then

winmain.innerhtml = changevbs(winmain.innertext)

else 'cmd腳本

winmain.innerhtml = changecmd(winmain.innertext)

end if

end sub

'*******************************************************************'

'vbs轉(zhuǎn)換模塊

'*******************************************************************'

function changevbs(stext)

set re=new regexp

re.ignorecase =true

re.global=true

'注釋轉(zhuǎn)換

re.pattern = (\'.*)\r\n

stext = re.replace(stext,<font color=#339999>$1</font><p>)

'轉(zhuǎn)換符號(hào)為[藍(lán)色]

re.pattern = (\(|\)|\&|\+|\-|\*|\%|\:|\;|\.|\ & )

stext = re.replace(stext,<font color=#993333>$1</font>)

stext = <table ><tr><td width='1024' & _

style='word-break:break-all'><ol type=1> & _

<br /><li> & stext & </table>

stext = replace(stext,chr(13) & chr (10) , </li><li> )

'轉(zhuǎn)換保留字為[藍(lán)色]

re.pattern=(\band\b|\bbyref\b|\bbyval\b|\bcall\b & _

|\bcase\b|\bclass\b|\bconst\b|\bdim\b|\bdo\b & _

|\beach\b|\belse\b|\belseif\b|\bempty\b|\bend\b & _

|\beqv\b|\berase\b|\berror\b|\bexit\b|\bexplicit\b & _

|\bfalse\b|\bfor\b|\bfunction\b|\bget\b|\bif\b|\bimp\b & _

|\bin\b|\bis\b|\blet\b|\bloop\b|\bmod\b|\bnext\b|\bnot\b & _

|\bnothing\b|\bnull\b|\bon\b|\boption\b|\bor\b|\bprivate\b & _

|\bproperty\b|\bpublic\b|\brandomize\b|\bredim\b|\brem\b & _

|\bresume\b|\bselect\b|\bset\b|\bstep\b|\bsub\b|\bthen\b & _

|\bto\b|\btrue\b|\buntil\b|\bwend\b|\bwhile\b|\bxor\b|vb[a-z]*)

stext=re.replace(stext,<font color=blue>$1</font>)

'轉(zhuǎn)換函數(shù)和對(duì)象為[紅色]

re.pattern=(\banchor\b|\barray\b|\basc\b|\batn\b & _

|\bcbool\b|\bcbyte\b|\bccur\b|\bcdate\b|\bcdbl\b & _

|\bchr\b|\bcint\b|\bclng\b|\bcos\b|\bcreateobject\b & _

|\bcsng\b|\bcstr\b|\bdate\b|\bdateadd\b|\bdatediff\b & _

|\bdatepart\b|\bdateserial\b|\bdatevalue\b|\bday\b & _

|\bdictionary\b|\bdocument\b|\belement\b|\berr\b|\bexp\b & _

|\bfilesystemobject \b|\bfilter\b|\bfix\b|\bint\b|\bform\b & _

|\bformatcurrency\b|\bformatdatetime\b|\bformatnumber\b & _

|\bformatpercent\b|\bgetobject\b|\bhex\b|\bhistory\b|\bhour\b & _

|\binputbox\b|\binstr\b|\binstrrev\b|\bisarray\b|\bisdate\b & _

|\bisempty\b|\bisnull\b|\bisnumeric\b|\bisobject\b|\bjoin\b & _

|\blbound\b|\blcase\b|\bleft\b|\blen\b|\blink\b|\bloadpicture\b & _

|\blocation\b|\blog\b|\bltrim\b|\brtrim\b|\btrim\b|\bmid\b & _

|\bminute\b|\bmonth\b|\bmonthname\b|\bmsgbox\b|\bnavigator\b & _

|\bnow\b|\boct\b|\breplace\b|\bright\b|\brnd\b|\bround\b & _

|\bscriptengine\b|\bscriptenginebuildversion\b & _

|\bscriptenginemajorversion\b|\bscriptengineminorversion\b & _

|\bsecond\b|\bsgn\b|\bsin\b|\bspace\b|\bsplit\b|\bsqr\b & _

|\bstrcomp\b|\bstring\b|\bstrreverse\b|\btan\b|\btime\b & _

|\btextstream\b|\btimeserial\b|\btimevalue\b|\btypename\b & _

|\bubound\b|\bucase\b|\bvartype\b|\bweekday\b|\bweekdayname\b & _

|\bwindow\b|\byear\b|\bwscript\b)

stext=re.replace(stext,<font color=red>$1</font>)

changevbs = stext

end function

'*******************************************************************'

'cmd轉(zhuǎn)換模塊

'*******************************************************************'

function changecmd(stext)

set re=new regexp

re.ignorecase =true

re.global=true

'等號(hào)轉(zhuǎn)換

'stext = replace(stext,/,<font color=#ff0000>/</font>)

re.pattern = (\%|\=|\/[a-z]*\b|\>|\<|\|)

stext = re.replace(stext,<font color=#ff8c00>$1</font>)

'注釋轉(zhuǎn)換

re.pattern = (rem\b.*\r\n|\brem\b.*)

stext = re.replace(stext,<font color=#20b2aa>$1</font>)

'改變符號(hào)的顏色

re.pattern = (\(|\)|\&|\+|\-|\*|\;|\ & )

stext = re.replace(stext,<font size=5 color=#9932cc>$1</font>)

'改變所有命令的顏色

re.pattern = (\bshare\b|\bsetver\b|\bnlsfunc\b|\bmem\b|\blh\b & _

|\bloadhigh\b|\bloadfix\b|\bgraphics\b|\bforcedos\b & _

|\bfastopen\b|\bexe2bin\b|\bedlin\b|\bedlin\b|\bedit\b & _

|\bdebug\b|\bdebug\b|\bappend\b|\bswitches\b|\bstacks\b & _

|\bshell\b|\bntcmdprompt\b|\blastdrive\b|\binstall\b & _

|\bfiles\b|\bfcbs\b|\bechoconfig\b|\bdriveparm\b|\bdosonly\b & _

|\bdos\b|\bdevicehigh\b|\bdevice\b|\bcountry\b|\bbuffers\b & _

|\bxcopy\b|\bwmic\b|\bwinnt32\b|\bwinnt\b|\bw32tm\b & _

|\bvssadmin\b|\bvol\b|\bverify\b|\bver\b|\bunlodctr\b & _

|\btypeperf\b|\btype\b|\btree\b|\btracert\b|\btracerpt\b & _

|\btitle\b|\btime\b|\btftp\b|\btelnet\b|\btcmsetup\b & _

|\btasklist\b|\btaskkill\b|\bsfc\b|\bsysteminfo\b|\bsubst\b & _

|\bstart\b|\bsort\b|\bshutdown\b|\bshift\b|\bsetlocal\b|\bset\b & _

|\bsecedit\b|\bschtasks\b|\bsc\b|\brunas\b|\brsm\b|\brsh\b & _

|\broute\b|\brmdir\b|\brexec\b|\breset\b|\breplace\b|\brename\b & _

|\brelog\b|\bregsvr32\b|\breg\b|\brecover\b|\brcp\b|\brasdial\b & _

|\bquery\b|\bpushd\b|\bprompt\b|\bprnqctl\b|\bprnport\b & _

|\bprnmngr\b|\bprnjobs\b|\bprndrvr\b|\bprncnfg\b|\bprint\b & _

|\bpopd\b|\bping\b|\bperfmon\b|\bpentnt\b|\bpbadmin\b|\bpause\b & _

|\bpathping\b|\bpath\b|\bpagefileconfig\b|\bopenfiles\b|\bntsd\b & _

|\bntcmdprompt\b|\bntbackup\b|\bnslookup\b|\bnetstat\b|\bnetsh\b & _

|\bnet\b|\bnbtstat\b|\bmsinfo32\b|\bmsiexec\b|\bmove\b & _

|\bmountvol\b|\bmore\b|\bmode\b|\bmmc\b|\bmd\b|\bmkdir\b & _

|\bmacfile\b|\blpr\b|\blpq\b|\blogman\b|\blodctr\b|\blabel\b & _

|\birftp\b|\bipxroute\b|\bipseccmd\b|\bipconfig\b|\bif\b & _

|\bhostname\b|\bhelpctr\b|\bhelp\b|\bgraftabl\b|\bgpupdate\b & _

|\bgpresult\b|\bgoto\b|\bgetmac\b|\bftype\b|\bftp\b|\bfsutil\b & _

|\bformat\b|\bfor\b|\bflattemp\b|\bfinger\b|\bfindstr\b|\bfind\b & _

|\bfc\b|\bexpand\b|\bexit\b|\bevntcmd\b|\beventtriggers\b & _

|\beventquery\b|\beventcreate\b|\bendlocal\b|\becho\b & _

|\bdriverquery\b|\bdoskey\b|\bdiskpart\b|\bdiskcopy\b & _

|\bdiskcomp\b|\bdir\b|\bdel\b|\bdefrag\b|\bdate\b|\bcscript\b & _

|\bcprofile\b|\bcopy\b|\bconvert\b|\bcompact\b|\bcomp\b & _

|\bcmstp\b|\bcmd\b|\bcls\b|\bcipher\b|\bchkntfs\b|\bchkdsk\b & _

|\bchdir\b|\bchcp\b|\bchange\b|\bcall\b|\bcacls\b|\bbreak\b & _

|\bbootcfg\b|\battrib\b|\batmadm\b|\bat\b|\bassoc\b|\barp\b)

stext=re.replace(stext,<font color=blue>$1</font>)

stext = <table><td width=1024 & _

style=word-break:break-all><ol type=1> & _

<br /><li> & stext & <tr></table>

stext = replace(stext,chr(13) & chr (10) , </li><li> )

changecmd = stext

end function

'*******************************************************************'

'幫助窗口

'*******************************************************************'

set opopup = window.createpopup

sub helpwindow

if usehelp.checked then

set opopbody = opopup.document.body

opopbody.style.backgroundcolor = lightyellow

opopbody.style.border = solid black 1px

opopbody.innerhtml = 幫助功能未完成,取消幫助見右下角

opopup.show winmain.offsetleft, _

winmain.offsettop + winmain.offsetheight - 20, _

winmain.offsetwidth, 20, document.body

end if

end sub

'*******************************************************************'

'運(yùn)行代碼

'*******************************************************************'

sub runcode

if cxs.value = vbs then

tmpfile = temp_script.vbs

str = tmpfile

else

tmpfile = temp_script.bat

str = cmd /k & tmpfile

end if

set file = fso.opentextfile(tmpdir & tmpfile,2,true)

file.write winmain.innertext

file.close

shell.run str

end sub

'*******************************************************************'

'保存文件

'*******************************************************************'

sub savefile

set objdialog = createobject(safrcfiledlg.filesave)

objdialog.filename = cstr(date)

if cxs.value = vbs then

objdialog.filetype = .vbs

else

objdialog.filetype = .bat

end if

intreturn = objdialog.openfilesavedlg

if intreturn then

set objfile = fso.createtextfile( _

objdialog.filename & objdialog.filetype)

objfile.writeline winmain.innertext

objfile.close

end if

end sub

'*******************************************************************'

'打開文件

'*******************************************************************'

sub openfile

set objdialog = createobject(useraccounts.commondialog)

objdialog.filter = bat文件|*.bat;*.cmd|vbs 文件|*.vbs|所有文件|*.*

'objdialog.maxfilesize = 10000

'objdialog.filterindex = 1

'objdialog.initialdir =

objdialog.showopen

'strloadfile = objdialog.filename

if len(trim(objdialog.filename)) = 0 then exit sub

set objfile = fso.opentextfile(objdialog.filename,1,true)

winmain.innertext = objfile.readall

end sub

'*******************************************************************'

'啟動(dòng)時(shí)自動(dòng)移動(dòng)到屏幕中心

'*******************************************************************'

sub window_onload()

self.resizeto 1,1

self.moveto 300,300

'顯示一個(gè)窗口

set objwindow = window.open(about:blank,progresswindow,height=15,width=250,left=300,top=300,status=no,titlebar=no,toolbar=no,menubar=no,location=no,scrollbars=no)

with objwindow

.focus()

.resizeto 250,15

.document.body.style.fontfamily = helvetica

.document.body.style.fontsize = 11pt

.document.writeln <html><body>正在搜索本地文件....</body></html>

.document.title = 請(qǐng)稍侯...

.document.body.style.backgroundcolor = buttonface

.document.body.style.borderstyle = none

.document.body.style.margintop = 15

end with

'如果系統(tǒng)并非xp,ie不為6.0版本則退出

strwindowsver = shell.regread _

(hklm\software\microsoft\windows nt\currentversion\productname)

striever = shell.regread _

(hklm\software\microsoft\internet explorer\version)

if strwindowsver <> microsoft windows xp or _

left(striever,3) <> 6.0 then

intflag = msgbox(操作系統(tǒng)不是xp或者ie版本低于6.0,是否退出?,1)

if intflag = 1 then

self.close

else

began

end if

else

began

end if

objwindow.close

end sub

sub began

optionadd bat

intleft = (document.parentwindow.screen.availwidth - 800) / 2

inttop = (document.parentwindow.screen.availheight - 600) / 2

window.resizeto 800,650

window.moveto intleft, inttop

end sub

'*******************************************************************'

'搜索本地腳本

'*******************************************************************'

sub testsub

set objfile = fso.opentextfile(objoption.value,1,true)

winmain.innertext = objfile.readall

end sub

'*******************************************************************'

'擦屁股

'*******************************************************************'

sub window_onbeforeunload()

on error resume next

fso.deletefile temp_script.vbs,true

fso.deletefile temp_script.bat,true

set shell = nothing

set fso = nothing

set opopup= nothing

end sub

'*******************************************************************'

'清空代碼

'*******************************************************************'

sub clear

winmain.innertext =

'winmain.innerhtml =

end sub

'*******************************************************************'

'復(fù)制到剪貼板

'*******************************************************************'

sub clipboard

window.clipboarddata.setdata text, winmain.innerhtml

end sub

</script>

</head>

<body>

<style type=text/css>

* { padding:0; border:0; overflow:hidden; font:16px arial;}

html,body { height:100%; margin:0;}

#box_2 { height:100%; background:#ccc;}

</style>

<center>

<div style=font-family: trebuchet ms; font-weight:bold;>

<span style=font-size: 18pt;>代碼編輯器</span>

<span style=font-size: 8pt;>ver 1.0 by

<a href=http://www.cn-dos.net/forum/forumdisplay.php?fid=23>

3742668</a>   <a href=mailto:3742668@gmail.com>

我的信箱</a></span><br></div></center><br> <div contenteditable

style=padding:2; overflow:auto;background-color:lightyellow;

width:100%; height:70%; id=winmain onkeyup=helpwindow>

</div> <br> <center>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=打開文件(x)

accesskey=x onclick=openfile>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=運(yùn)行代碼(r)

accesskey=r onclick=runcode>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=清空代碼(c)

accesskey=c onclick=clear>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=保存文件(s)

accesskey=s onclick=savefile>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=復(fù)制著色代碼(a)

accesskey=a onclick=clipboard>

<input style=font-family: trebuchet ms; font-size: 8pt; font-weight:

bold; border: 1px solid black; type=button value=著色顯示(d)

accesskey=d onclick=changecolor></center>

<br><div id=foroption></div><p>

<input type=checkbox id=usehelp onfocus=winmain.focus

accesskey=z class=noborder position: checked>

<label for=usehelp>使用幫助(<u>z</u>)</label>  

   <label>腳本類型:<label>

<select name=cxs size=1 onchange=optionadd(cxs.value)>

<option value=vbs>

vbs腳本</option><option value=bat selected>bat腳本</option><br>

</body>

</html> 

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:winxp下用vbs寫的代碼編輯器
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)