-
Notifications
You must be signed in to change notification settings - Fork 9
/
文件夹显示伪名.vbs
100 lines (82 loc) · 5.13 KB
/
文件夹显示伪名.vbs
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
94
95
96
97
98
99
100
Dim Files,customName
Set Files = WScript.Arguments '将参数(文件列表)存入类
Dim fso,oShell
Set fso = CreateObject("scripting.filesystemobject") '文件操作系统对象
If fso.FolderExists(Files(0)) Then
customName = InputBox("请输入需要显示的名称(特殊字符亦可)","输入名称")
If Len(customName) < 1 Then
WScript.Quit
End If
Dim iniPath
iniPath = Files(0) & "\desktop.ini"
If fso.FileExists(iniPath) Then
fso.GetFile(iniPath).Attributes =0
End If
SetIniValue Files(0) & "\desktop.ini",".ShellClassInfo","LocalizedResourceName",customName
fso.GetFile(iniPath).Attributes = 2 + 4 + 32
' fso.GetFolder(Files(0)).Attributes = 16
oldAttributes = fso.GetFolder(Files(0)).Attributes
fso.GetFolder(Files(0)).Attributes = 1 + 16 + 2 + 4
fso.GetFolder(Files(0)).Attributes = oldAttributes
' Set oShell = CreateObject("WScript.Shell")
' oShell.Run "ATTRIB +R """ & Files(0) & """"
Else
ShowLog Files(0) & vbCrLf & "不是文件夹或文件夹不存在"
WScript.Quit
End If
Set fso = Nothing
'显示日志
Function ShowLog(str)
WScript.Echo str
End Function
'是否符合正则表达式
Function RegExpTest(strng, patrn)
Dim regEx ' 创建变量。
Set regEx = New RegExp ' 创建正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写,True为不区分。
regEx.Global = True ' 设置全程匹配。
regEx.MultiLine = True
RegExpTest = regEx.Test(strng) ' 执行搜索。
Set regEx = Nothing
End Function
'函数:设置ini值(ini路径,目标节点,目标键,目标值)
'注:若ini文件不存在则创建;节点或键不存在则添加
Function SetIniValue(path, sectionName, keyName, value)
Dim fsot,file
Set fsot = CreateObject("Scripting.FileSystemObject")
Set file = fsot.OpenTextFile(path, 1,True,-2)
Dim line, cache, inSection, sectionExist, keyExist
Do Until file.AtEndOfStream
line = file.Readline
If StrComp(Trim(line),"["+sectionName+"]",1)=0 Then
inSection=True
sectionExist=True
End If
If inSection And Left(LTrim(line),1)="[" And StrComp(Trim(line),"["+sectionName+"]",1)<>0 Then
inSection=False
If Not keyExist Then
cache = cache + keyName+"="+value+vbCrLf
keyExist=True
End If
End If
If inSection And InStr(line,"=")<>0 Then
ss = Split(line,"=")
If StrComp(Trim(ss(0)),keyName,1)=0 Then
line = ss(0)+"="+value
keyExist = True
End If
End If
cache=cache+line+vbCrLf
Loop
file.Close
If Not sectionExist Then
cache = cache + "["+sectionName+"]"+vbCrLf
cache = cache + keyName+"="+value+vbCrLf
ElseIf Not keyExist Then
cache = cache + keyName+"="+value+vbCrLf
End If
Set file = fsot.OpenTextFile(path, 2, True, -1)
file.Write(cache)
file.Close
End Function