forked from Ardmore1/SWIFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.vb
1425 lines (1417 loc) · 70.6 KB
/
MainForm.vb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'Program written by Rick ardmore for the purpose of helping
'The IT tech support folk and engineers quickly find employees
'IP address, last PC they logged into, remote controll the PC,
'Get database information out of ConfigMGR about the PC,
'reset Ad passwords, connect to PC functions such as manage this PC,
'Get logon history, unlock accounts and much much more
'This tool set allows level1 techs to make use of the common features in
'ConfigMGR and Active directory without having to know how to use either...
Imports System.Text
Imports System.Security.Cryptography
Imports System.Security.AccessControl
Imports System.IO
Imports System.Security
Imports System.Security.Principal
Imports System.DirectoryServices
Imports System.Management
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Win32
Public Class frmMainForm
'List of people. Later I plan to check AD for this list
Dim TechOps As String = "shoops,rick-,dshank,chetrick,schroedr,cbarrick,dustin,rice,benboyles"
Dim TheADPGroup As String = ""
Dim MeGroups() As String = Nothing
Public tHEpROCmACHINE As String = ""
Public TheSaltValue As String 'set in INI
Public passIterations As Integer = 2
Public TheinitialVector As String 'set in INI
Public TheAESpassPhrase As String 'set in INI
Public ThekeySize As Integer 'set in INI
Public TheDomain As String 'set in INI
Public TheDomainRoot As String 'set in INI
Public LDAPBaseDN As String 'set in INI
Public SMSServer As String 'set in INI
Public SMSServerDB As String 'set in INI
Public usrLogPath As String 'set in INI
Public SMSDB As String 'set in INI
Public usrLogonDB As String 'set in INI
Public driveMapScriptLocation As String 'set in INI
Public userLDAPPaths As List(Of String) = New List(Of String) 'set in INI
Public computerLDAPPaths As List(Of String) = New List(Of String) 'set in INI
Private Sub GetTheINIs()
'read in all the INI values and assign them to their vars
If Not File.Exists(IO.Directory.GetCurrentDirectory() & "\config.ini") Then
MessageBox.Show("config.ini is missing.")
Exit Sub
End If
Dim objFileReader As New StreamReader("config.ini")
Dim TheTextLine() As String
Do While objFileReader.Peek() <> -1
Try
TheTextLine = objFileReader.ReadLine().Split(Chr(9))
If TheTextLine(0).ToLower = "thesaltvalue" Then
TheSaltValue = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "theinitialvector" Then
TheinitialVector = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "thekeysize" Then
ThekeySize = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "theaespassphrase" Then
TheAESpassPhrase = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "thedomain" Then
TheDomain = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "thedomainroot" Then
TheDomainRoot = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "ldapbasedn" Then
LDAPBaseDN = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "smsserver" Then
SMSServer = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "smsserverdb" Then
SMSServerDB = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "usrlogpath" Then
usrLogPath = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "smsdb" Then
SMSDB = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "usrlogondb" Then
usrLogonDB = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "drivemapscriptlocation" Then
driveMapScriptLocation = TheTextLine(1)
End If
If TheTextLine(0).ToLower = "acomputerldappath" Then
computerLDAPPaths.Add(TheTextLine(1))
End If
If TheTextLine(0).ToLower = "auserldappath" Then
userLDAPPaths.Add(TheTextLine(1))
End If
Catch ex As Exception
End Try
Loop
objFileReader.Close()
End Sub
Public Sub UpdateADMainPGDB()
'Clear all the forms and vars
Try
Dim strOfficeM As String = "na"
Dim strTelM As String = "na"
Dim strStreetM As String = "na"
Dim strCityM As String = "na"
Dim strStateM As String = "na"
Dim strZipM As String = "na"
Dim strCountryM As String = "na"
Dim strFaxM As String = "na"
Dim strCompanyM As String = "na"
Dim strtitle As String = "na"
Dim strDept As String = "na"
If tbxTitle.Text = "" Then
MessageBox.Show("Please enter a title.")
Exit Sub
Else
strtitle = tbxTitle.Text
End If
If tbxDept.Text = "" Then
MessageBox.Show("Please enter a department.")
Exit Sub
Else
strDept = tbxDept.Text
End If
If tbxOffice.Text = "" Then
MessageBox.Show("Please enter an office.")
Exit Sub
Else
strOfficeM = tbxOffice.Text
End If
If tbxCompany.Text = "" Then
MessageBox.Show("Please enter a company.")
Exit Sub
Else
strCompanyM = tbxCompany.Text
End If
If tbxAddress.Text = "" Then
MessageBox.Show("Please enter an address.")
Exit Sub
Else
strStreetM = tbxAddress.Text
End If
If tbxCity.Text = "" Then
MessageBox.Show("Please enter a city.")
Exit Sub
Else
strCityM = tbxCity.Text
End If
If cboState.Text = "" Then
MessageBox.Show("Please enter a state.")
Exit Sub
Else
strStateM = cboState.Text
End If
If tbxZip.Text = "" Then
MessageBox.Show("Please enter a zip code.")
Exit Sub
Else
strZipM = tbxZip.Text
End If
If tbxTel.Text = "" Then
MessageBox.Show("Please enter a telephone number.")
Exit Sub
Else
strTelM = tbxTel.Text
End If
If tbxFax.Text = "" Then
MessageBox.Show("Please enter a fax number.")
Exit Sub
Else
strFaxM = tbxFax.Text
End If
Dim auser As String = tbxUserName.Text
Dim userLDAPpath As String
Dim notFound As Boolean = True
For Each userLDAPpath In userLDAPPaths
Dim dirEntry As New DirectoryEntry("LDAP://" & userLDAPpath)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(|(SAMAccountName=" & auser & ")(cn=" & auser & ")))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
notFound = False
Dim dirEntryResults As New DirectoryEntry(results.Path)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
dirEntryResults.Properties("physicalDeliveryOfficeName").Value = strOfficeM
dirEntryResults.Properties("telephoneNumber").Value = strTelM
dirEntryResults.Properties("streetAddress").Value = strStreetM
dirEntryResults.Properties("l").Value = strCityM
dirEntryResults.Properties("st").Value = strStateM
dirEntryResults.Properties("postalCode").Value = strZipM
dirEntryResults.Properties("facsimileTelephoneNumber").Value = strFaxM
dirEntryResults.Properties("company").Value = strCompanyM
dirEntryResults.Properties("title").Value = strtitle
dirEntryResults.Properties("department").Value = strDept
If TextBoxCellPhone.Text <> "" Then
dirEntryResults.Properties("mobile").Value = TextBoxCellPhone.Text
End If
If TextBoxDiscription.Text <> "" Then
dirEntryResults.Properties("Description").Value = TextBoxDiscription.Text
End If
If dirEntryResults.SchemaClassName = "user" Then
If tbxProfilePath.Text <> "" Then
dirEntryResults.Properties("profilePath").Value = tbxProfilePath.Text
Else
dirEntryResults.Properties("profilePath").Clear()
End If
End If
dirEntryResults.CommitChanges()
dirEntryResults.Close()
MessageBox.Show("Success! " & auser & "'s info has been updated.")
Else
End If
dirEntry.Close()
Next
If notFound Then
MessageBox.Show("Error!" & vbCrLf & "Cannot locate this user.")
End If
Catch ex As Exception
MessageBox.Show("Unfortunately you do not have permission to update one of the feilds.")
End Try
End Sub
Public Shared Function BeDecrypted(ByVal cipherText As String, ByVal passPhrase As String, _
ByVal saltyValue As String, ByVal hashAlgorithm As String, _
ByVal passwordIterations As Integer, ByVal initVector As String, _
ByVal keySize As Integer) As String
'This function decrypts the EmployeeID feild in Active Directory. The company wanted to make sure no one could read the feild by browsing though active directory.
Dim initVectorBytes As Byte()
initVectorBytes = Encoding.ASCII.GetBytes(initVector)
Dim saltyBytes As Byte()
saltyBytes = Encoding.ASCII.GetBytes(saltyValue)
Dim cipherTextBytes As Byte()
cipherTextBytes = Convert.FromBase64String(cipherText)
Dim Apassword As PasswordDeriveBytes
Apassword = New PasswordDeriveBytes(passPhrase, saltyBytes, hashAlgorithm, passwordIterations)
Dim keyBytes As Byte()
keyBytes = Apassword.GetBytes(keySize / 8)
Dim TheSymmetricAKAsingleKey As RijndaelManaged
TheSymmetricAKAsingleKey = New RijndaelManaged()
TheSymmetricAKAsingleKey.Mode = CipherMode.CBC
Dim TheDecryptor As ICryptoTransform
TheDecryptor = TheSymmetricAKAsingleKey.CreateDecryptor(keyBytes, initVectorBytes)
Dim SomeMemoryStream As MemoryStream
SomeMemoryStream = New MemoryStream(cipherTextBytes)
Dim SomeCryptoStream As CryptoStream
SomeCryptoStream = New CryptoStream(SomeMemoryStream, TheDecryptor, CryptoStreamMode.Read)
Dim TheBitesOfPlainText As Byte()
ReDim TheBitesOfPlainText(cipherTextBytes.Length)
Dim decryptedByteCount As Integer
decryptedByteCount = SomeCryptoStream.Read(TheBitesOfPlainText, 0, TheBitesOfPlainText.Length)
SomeMemoryStream.Close()
SomeCryptoStream.Close()
Dim ThePlainText As String
ThePlainText = Encoding.UTF8.GetString(TheBitesOfPlainText, 0, decryptedByteCount)
BeDecrypted = ThePlainText
End Function
Public Shared Function BeEncrypted(ByVal plainText As String, ByVal passPhrase As String, _
ByVal SaltyValue As String, ByVal hashAlgorithm As String, _
ByVal passwordIterations As Integer, ByVal initVector As String, _
ByVal keySize As Integer) As String
'This function encrypts the EmployeeID feild in Active Directory. The company wanted to make sure no one could read the feild by browsing though active directory.
Dim initVectorBytes As Byte()
initVectorBytes = Encoding.ASCII.GetBytes(initVector)
Dim SaltyBytes As Byte()
SaltyBytes = Encoding.ASCII.GetBytes(SaltyValue)
Dim plainTextBytes As Byte()
plainTextBytes = Encoding.UTF8.GetBytes(plainText)
Dim Apassword As PasswordDeriveBytes
Apassword = New PasswordDeriveBytes(passPhrase, SaltyBytes, hashAlgorithm, passwordIterations)
Dim keyBytes As Byte()
keyBytes = Apassword.GetBytes(keySize / 8)
Dim TheSymmetricAKAsingleKey As RijndaelManaged
TheSymmetricAKAsingleKey = New RijndaelManaged()
TheSymmetricAKAsingleKey.Mode = CipherMode.CBC
Dim encryptor As ICryptoTransform
encryptor = TheSymmetricAKAsingleKey.CreateEncryptor(keyBytes, initVectorBytes)
Dim SomeMemoryStream As MemoryStream
SomeMemoryStream = New MemoryStream()
Dim SomeCryptoStream As CryptoStream
SomeCryptoStream = New CryptoStream(SomeMemoryStream, encryptor, CryptoStreamMode.Write)
SomeCryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
SomeCryptoStream.FlushFinalBlock()
Dim TextOcipher As Byte()
TextOcipher = SomeMemoryStream.ToArray()
SomeMemoryStream.Close()
SomeCryptoStream.Close()
Dim TheCipherText As String
TheCipherText = Convert.ToBase64String(TextOcipher)
BeEncrypted = TheCipherText
End Function
Public Sub GetADInfo()
'This sub searches Ad for the username or partial username that is entered into the form.
Try
Dim strOfficeM As String = "na"
Dim strTelM As String = "na"
Dim strStreetM As String = "na"
Dim strCityM As String = "na"
Dim strStateM As String = "na"
Dim strZipM As String = "na"
Dim strCountryM As String = "na"
Dim strFaxM As String = "na"
Dim strCompanyM As String = "na"
Dim strtitle As String = "na"
Dim strDept As String = "na"
Dim expiredate As DateTime
Dim vGroups As Array
Dim UsersAccountStatus As Boolean
Dim ImEnabledMa As Boolean
If tbxUserName.Text = "" Then
MessageBox.Show("Please enter a user first.")
Exit Sub
End If
'Search ALL of domain (from base) if ur a sweet admin, else only search specified userLDAPpaths
If GetCurrentUserGroups() Then
Dim dirEntry As New DirectoryEntry("LDAP://" & LDAPBaseDN)
Dim auser As String = tbxUserName.Text
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(|(SAMAccountName=" & auser & ")(cn=" & auser & ")))"
dirSearcher.PropertiesToLoad.Add("createTimeStamp")
dirSearcher.PropertiesToLoad.Add("modifyTimeStamp")
dirSearcher.PropertiesToLoad.Add("canonicalName")
dirSearcher.PropertiesToLoad.Add("pwdLastSet")
dirSearcher.PropertiesToLoad.Add("description")
dirSearcher.PropertiesToLoad.Add("info")
dirSearcher.PropertiesToLoad.Add("adminDisplayName")
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(results.Path)
dirEntryResults.Username = Nothing
dirEntryResults.Password = Nothing
dirEntryResults.AuthenticationType = AuthenticationTypes.Secure
tbxTitle.Text = dirEntryResults.Properties("title").Value
tbxDept.Text = dirEntryResults.Properties("department").Value
tbxOffice.Text = dirEntryResults.Properties("physicalDeliveryOfficeName").Value
tbxCompany.Text = dirEntryResults.Properties("company").Value
tbxAddress.Text = dirEntryResults.Properties("streetAddress").Value
tbxCity.Text = dirEntryResults.Properties("l").Value
cboState.Text = dirEntryResults.Properties("st").Value
tbxZip.Text = dirEntryResults.Properties("postalCode").Value
TextBoxCellPhone.Text = dirEntryResults.Properties("mobile").Value
tbxTel.Text = dirEntryResults.Properties("telephoneNumber").Value
If Not dirEntryResults.Properties("employeeNumber").Value Is Nothing Then
LabelADPID.Text = BeDecrypted(dirEntryResults.Properties("employeeNumber").Value, TheAESpassPhrase,
TheSaltValue, "SHA1", 2, TheinitialVector, ThekeySize)
LabelADPID.ForeColor = Color.Blue
Else
LabelADPID.Text = "Null"
LabelADPID.ForeColor = Color.Red
End If
Try
TextBoxADPName.Text = dirEntryResults.Properties("adminDisplayName").Value.ToString
TextBoxADPName.ForeColor = Color.Blue
Catch ex As Exception
TextBoxADPName.Text = "Null"
TextBoxADPName.ForeColor = Color.Red
End Try
Try
ImEnabledMa = Boolean.Parse(dirEntryResults.Properties("msRTCSIP-UserEnabled").Value.ToString)
If ImEnabledMa Then
LabelHasIM.Text = True
LabelHasIM.ForeColor = Color.Green
End If
Catch ex As Exception
LabelHasIM.Text = False
LabelHasIM.ForeColor = Color.Blue
End Try
tbxFax.Text = dirEntryResults.Properties("facsimileTelephoneNumber").Value
txtCreationDate.Text = Format(results.Properties("createTimeStamp")(0), "M-d-yy h:mm tt")
txtLastModified.Text = Format(results.Properties("modifyTimeStamp")(0), "M-d-yy h:mm tt")
txtDisplayName.Text = dirEntryResults.Properties("displayName").Value
LabelADPath.Text = results.Properties("canonicalName")(0)
LabelADPath.Text = LabelADPath.Text.Replace("/", "\").Replace(TheDomainRoot + "\", "")
lblObjType.Text = dirEntryResults.SchemaClassName
Try
TextBoxDiscription.Text = dirEntryResults.Properties("description").Value.ToString
Catch ex As Exception
End Try
If dirEntryResults.SchemaClassName = "user" Then
txtLocked.Text = dirEntryResults.InvokeGet("IsAccountLocked")
UsersAccountStatus = Boolean.Parse(dirEntryResults.InvokeGet("AccountDisabled"))
If UsersAccountStatus Then
LabelUserActStat.Text = "Account Disabled"
LabelUserActStat.ForeColor = Color.Red
Else
LabelUserActStat.Text = "Active"
LabelUserActStat.ForeColor = Color.Green
End If
If txtLocked.Text = "True" Then
txtLocked.ForeColor = Color.Red
txtLocked.Font = New Font(Label1.Font, FontStyle.Bold)
Else
txtLocked.ForeColor = Color.Green
End If
txtpwdlastset.Text = Format(DateTime.FromFileTime(results.Properties("pwdLastSet")(0)), "M-d-yy h:mm tt")
tbxProfilePath.Text = dirEntryResults.Properties("profilePath").Value
expiredate = Format(DateTime.FromFileTime(results.Properties("pwdLastSet")(0)), "M-d-yy h:mm tt")
txtPassExpire.Text = Format(expiredate.AddDays(90), "M-d-yy h:mm tt")
End If
Dim groupEntry As String
Dim groupEntryR As String
Dim groupEntryS As Array
cboMemberOf.Items.Clear()
If IsArray(dirEntryResults.InvokeGet("memberOf")) Then
vGroups = dirEntryResults.InvokeGet("memberOf")
If Not vGroups Is Nothing Then
For Each groupEntry In vGroups
groupEntryR = Mid(groupEntry, 4)
groupEntryS = Split(groupEntryR, ",")
cboMemberOf.Items.Add(groupEntryS(0))
Next
End If
End If
dirEntryResults.Close()
Else
FoundUsers.Show()
End If
dirEntry.Close()
Else
Dim userLDAPpath As String
Dim notFound As Boolean = True
For Each userLDAPpath In userLDAPPaths
Dim dirEntry As New DirectoryEntry("LDAP://" & userLDAPpath)
Dim auser As String = tbxUserName.Text
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(|(SAMAccountName=" & auser & ")(cn=" & auser & ")))"
dirSearcher.PropertiesToLoad.Add("createTimeStamp")
dirSearcher.PropertiesToLoad.Add("modifyTimeStamp")
dirSearcher.PropertiesToLoad.Add("canonicalName")
dirSearcher.PropertiesToLoad.Add("pwdLastSet")
dirSearcher.PropertiesToLoad.Add("description")
dirSearcher.PropertiesToLoad.Add("info")
dirSearcher.PropertiesToLoad.Add("adminDisplayName")
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
notFound = False
Dim dirEntryResults As New DirectoryEntry(results.Path)
dirEntryResults.Username = Nothing
dirEntryResults.Password = Nothing
dirEntryResults.AuthenticationType = AuthenticationTypes.Secure
tbxTitle.Text = dirEntryResults.Properties("title").Value
tbxDept.Text = dirEntryResults.Properties("department").Value
tbxOffice.Text = dirEntryResults.Properties("physicalDeliveryOfficeName").Value
tbxCompany.Text = dirEntryResults.Properties("company").Value
tbxAddress.Text = dirEntryResults.Properties("streetAddress").Value
tbxCity.Text = dirEntryResults.Properties("l").Value
cboState.Text = dirEntryResults.Properties("st").Value
tbxZip.Text = dirEntryResults.Properties("postalCode").Value
TextBoxCellPhone.Text = dirEntryResults.Properties("mobile").Value
tbxTel.Text = dirEntryResults.Properties("telephoneNumber").Value
If Not dirEntryResults.Properties("employeeNumber").Value Is Nothing Then
LabelADPID.Text = BeDecrypted(dirEntryResults.Properties("employeeNumber").Value, TheAESpassPhrase,
TheSaltValue, "SHA1", 2, TheinitialVector, ThekeySize)
LabelADPID.ForeColor = Color.Blue
Else
LabelADPID.Text = "Null"
LabelADPID.ForeColor = Color.Red
End If
Try
TextBoxADPName.Text = dirEntryResults.Properties("adminDisplayName").Value.ToString
TextBoxADPName.ForeColor = Color.Blue
Catch ex As Exception
TextBoxADPName.Text = "Null"
TextBoxADPName.ForeColor = Color.Red
End Try
Try
ImEnabledMa = Boolean.Parse(dirEntryResults.Properties("msRTCSIP-UserEnabled").Value.ToString)
If ImEnabledMa Then
LabelHasIM.Text = True
LabelHasIM.ForeColor = Color.Green
End If
Catch ex As Exception
LabelHasIM.Text = False
LabelHasIM.ForeColor = Color.Blue
End Try
tbxFax.Text = dirEntryResults.Properties("facsimileTelephoneNumber").Value
txtCreationDate.Text = Format(results.Properties("createTimeStamp")(0), "M-d-yy h:mm tt")
txtLastModified.Text = Format(results.Properties("modifyTimeStamp")(0), "M-d-yy h:mm tt")
txtDisplayName.Text = dirEntryResults.Properties("displayName").Value
LabelADPath.Text = results.Properties("canonicalName")(0)
LabelADPath.Text = LabelADPath.Text.Replace("/", "\").Replace(TheDomainRoot + "\", "")
lblObjType.Text = dirEntryResults.SchemaClassName
Try
TextBoxDiscription.Text = dirEntryResults.Properties("description").Value.ToString
Catch ex As Exception
End Try
If dirEntryResults.SchemaClassName = "user" Then
txtLocked.Text = dirEntryResults.InvokeGet("IsAccountLocked")
UsersAccountStatus = Boolean.Parse(dirEntryResults.InvokeGet("AccountDisabled"))
If UsersAccountStatus Then
LabelUserActStat.Text = "Account Disabled"
LabelUserActStat.ForeColor = Color.Red
Else
LabelUserActStat.Text = "Active"
LabelUserActStat.ForeColor = Color.Green
End If
If txtLocked.Text = "True" Then
txtLocked.ForeColor = Color.Red
txtLocked.Font = New Font(Label1.Font, FontStyle.Bold)
Else
txtLocked.ForeColor = Color.Green
End If
txtpwdlastset.Text = Format(DateTime.FromFileTime(results.Properties("pwdLastSet")(0)), "M-d-yy h:mm tt")
tbxProfilePath.Text = dirEntryResults.Properties("profilePath").Value
expiredate = Format(DateTime.FromFileTime(results.Properties("pwdLastSet")(0)), "M-d-yy h:mm tt")
txtPassExpire.Text = Format(expiredate.AddDays(90), "M-d-yy h:mm tt")
End If
Dim groupEntry As String
Dim groupEntryR As String
Dim groupEntryS As Array
cboMemberOf.Items.Clear()
If IsArray(dirEntryResults.InvokeGet("memberOf")) Then
vGroups = dirEntryResults.InvokeGet("memberOf")
If Not vGroups Is Nothing Then
For Each groupEntry In vGroups
groupEntryR = Mid(groupEntry, 4)
groupEntryS = Split(groupEntryR, ",")
cboMemberOf.Items.Add(groupEntryS(0))
Next
End If
End If
dirEntryResults.Close()
End If
dirEntry.Close()
Next
If notFound Then
FoundUsers.Show()
End If
End If
Catch ex As Exception
MessageBox.Show("Error - there was an exception. Please report this bug to Rick or Dustin.")
End Try
End Sub
Public Sub WhosLoggedIn(ByVal MachineName As String)
'This sub connects to WMI on the target machine to respond with the presently logged on user account
Try
Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet
End With
Dim myManagementScope As System.Management.ManagementScope
Dim myServerName As String = MachineName
myManagementScope = New System.Management.ManagementScope("\\" & myServerName & "\root\cimv2", myConnectionOptions)
myManagementScope.Connect()
If myManagementScope.IsConnected = False Then
MsgBox("Error - could not connect.")
End If
Dim myObjectSearcher As System.Management.ManagementObjectSearcher
Dim myObjectCollection As System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
myObjectSearcher = New System.Management.ManagementObjectSearcher(myManagementScope.Path.ToString, "SELECT UserName from Win32_ComputerSystem")
myObjectCollection = myObjectSearcher.Get()
Dim luser
For Each myObject In myObjectCollection
If Not myObject("UserName") Is Nothing Then
luser = myObject("UserName").ToString
MessageBox.Show(luser & " is currently logged in")
Else
MessageBox.Show("No one is logged in")
End If
Next
Catch ex As Exception
MessageBox.Show("Problems Connecting to machine")
End Try
End Sub
Public Sub GetADComputerInfo()
'This sub searches Ad for the computer name or partial computer name that is entered into the form.
dgvComputerList.Rows.Clear()
Dim aComputer As String
If tbxPlistCname.Text = "" Then
MsgBox("Please enter a valid host.")
Exit Sub
End If
aComputer = LCase(tbxPlistCname.Text)
Dim count As Integer
Dim dirEntry As New DirectoryEntry("LDAP://" & LDAPBaseDN)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher
Dim resultCollection As SearchResultCollection
dirSearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=computer)(CN=" & aComputer & "))"
dirSearcher.PropertiesToLoad.Add("canonicalName")
dirSearcher.SearchScope = SearchScope.Subtree
resultCollection = dirSearcher.FindAll()
count = resultCollection.Count
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = count
Dim row1 As String
Dim row2 As String
If count > 0 Then
For i As Integer = 0 To count - 1 Step 1
row1 = resultCollection(i).GetDirectoryEntry.Properties("CN").Value
row2 = resultCollection(i).Properties("canonicalName")(0)
dgvComputerList.Rows.Add(row1, row2)
ProgressBar1.Value = i
Next i
Else
MsgBox("Error - could not find specified host.")
End If
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
dirEntry.Close()
End Sub
Public Sub GetADComputerInfo1()
'This sub searches Ad for the computer name or partial computer name that is entered into the form.
'This sub is just another variation of the other sub by the same name
dgvComputerList.Rows.Clear()
Dim count As Integer
Dim dirEntry As New DirectoryEntry("LDAP://" & LDAPBaseDN)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher
Dim resultCollection As SearchResultCollection
dirSearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(objectCategory=computer)"
dirSearcher.PropertiesToLoad.Add("canonicalName")
dirSearcher.PropertiesToLoad.Add("Lastlogon")
dirSearcher.PropertiesToLoad.Add("LastlogontimeStamp")
dirSearcher.SearchScope = SearchScope.Subtree
resultCollection = dirSearcher.FindAll()
count = resultCollection.Count
txtCount.Text = count & " Computers in this domain"
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = count
Dim row1 As String
Dim row2 As String
dgvComputerList.Rows.Clear()
If count > 0 Then
For i As Integer = 0 To count - 1 Step 1
row1 = resultCollection(i).GetDirectoryEntry.Properties("CN").Value
row2 = resultCollection(i).Properties("canonicalName")(0)
dgvComputerList.Rows.Add(row1, row2)
ProgressBar1.Value = i
Me.Refresh()
Next i
End If
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
dirEntry.Close()
End Sub
Public Sub AddRemoveProgram(ByVal MachineName As String)
' This Sub connects to WMI on the specified computer and then reads in the add remove program list for that PC
Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet
End With
Dim myManagementScope As System.Management.ManagementScope
Dim myServerName As String = MachineName
myManagementScope = New System.Management.ManagementScope("\" & myServerName & "\root\cimv2", myConnectionOptions)
myManagementScope.Connect()
If myManagementScope.IsConnected = False Then
MsgBox("Error - could not connect.")
End If
Dim myObjectSearcher As System.Management.ManagementObjectSearcher
Dim myObjectCollection As System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
myObjectSearcher = New System.Management.ManagementObjectSearcher(myManagementScope.Path.ToString, "Select * From Win32_Product")
myObjectCollection = myObjectSearcher.Get()
For Each myObject In myObjectCollection
Console.WriteLine(myObject.GetPropertyValue("Caption"))
Next
End Sub
Public Sub Unlock()
'This sub unlocks the specified user account in Active Directory
Try
If tbxUserName.Text = "" Then
MessageBox.Show("Please enter a user first.")
Exit Sub
End If
Dim auser As String = tbxUserName.Text
Dim dirEntry As New DirectoryEntry("LDAP://" & LDAPBaseDN)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(objectClass=user)(SAMAccountName=" & auser & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(results.Path)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
dirEntryResults.InvokeSet("IsAccountLocked", False)
dirEntryResults.CommitChanges()
dirEntryResults.Close()
MessageBox.Show("Success - user unlocked!")
Else
MessageBox.Show("Error - unable to locate specified user.")
End If
dirEntry.Close()
Catch ex As Exception
MessageBox.Show("Error - you do not have permission to unlock this user.")
End Try
End Sub
Function MegroupsCheck(ByVal TheGroupToCheck As String)
'Check what groups the user of this program belongs to
Try
For Each groupIgot As String In MeGroups
If groupIgot.IndexOf(TheGroupToCheck) <> -1 Then
Return True
Exit Function
End If
Next
Catch ex As Exception
End Try
Return False
End Function
Public Sub ClearExtraAccountInfo()
'Clears the extra account info text fields on the main form
txtLocked.Text = " "
cboMemberOf.Items.Clear()
txtCreationDate.Text = " "
txtLastModified.Text = " "
txtpwdlastset.Text = " "
txtPassExpire.Text = " "
lblObjType.Text = " "
txtDisplayName.Text = " "
LabelADPath.Text = " "
LabelUserActStat.Text = " "
LabelHasIM.Text = " "
LabelADPID.Text = " "
TextBoxADPName.Text = " "
If MegroupsCheck("canupdateempid") = True Then
ButtonUpdateADP.Visible = True
ButtonClearADP.Visible = True
End If
End Sub
Private Sub psexecKey()
'This program makes use of PSexec. This sub eliminates the first time popups when it is used on a new PC
Dim PSexecRegKey As RegistryKey
Dim strPsexecRegKey As String = "HKEY_CURRENT_USER\Software\Sysinternals\PsExec"
PSexecRegKey = Registry.CurrentUser.OpenSubKey("Software\Sysinternals\PsExec", True)
If PSexecRegKey Is Nothing Then
My.Computer.Registry.SetValue(strPsexecRegKey, "EulaAccepted", "1", Microsoft.Win32.RegistryValueKind.DWord)
End If
End Sub
Sub PsexecExist()
'Let's make sure PSexec exists on the local PC and put it there if it doesnt
Try
Dim FileDestination As String = "c:\windows\system32\psexec.exe"
Dim FileSource As String = "\\ccmfs\msipub$\Icons\psexec.exe"
If System.IO.File.Exists(FileDestination) = False Then
System.IO.File.Copy(FileSource, FileDestination, True)
End If
Catch ex As Exception
End Try
End Sub
Private Sub MakeDisableWallpaperBatch()
'This sub creates a batch file that hides the walpaper on the remote PC, which improves the remote control performance.
Try
Dim BatchFile1 As String = "c:\windows\DisableWallpaper.bat"
Dim ObjFileSystem As New IO.StreamWriter(BatchFile1, False)
ObjFileSystem.Write("reg add " & Chr(34) & "hkcu\control panel\desktop" & Chr(34) & " /v wallpaper /t REG_SZ /d " & Chr(34) & Chr(34) & " /f " & vbCrLf)
ObjFileSystem.Write("RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters")
ObjFileSystem.Close()
Dim BatchFile2 As String = "c:\windows\launchNotePad.bat"
Dim ObjFileSystem2 As New IO.StreamWriter(BatchFile2, False)
ObjFileSystem2.Write("start /max notepad")
ObjFileSystem2.Close()
Catch ex As Exception
End Try
End Sub
Public Sub GetADComputerInfoByDate()
'This sub loads a list of PC's in the domain who have not checked in With AD over a date that you select.
dgvComputerList.Rows.Clear()
Dim count As Integer
Dim dirEntry As New DirectoryEntry("LDAP://" & LDAPBaseDN)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher
Dim resultCollection As SearchResultCollection
dirSearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(objectCategory=computer)"
dirSearcher.PropertiesToLoad.Add("canonicalName")
dirSearcher.SearchScope = SearchScope.Subtree
resultCollection = dirSearcher.FindAll()
count = resultCollection.Count
txtCount.Text = count & " Computers in this domain"
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = count
Dim row1 As String
Dim row2 As String
dgvComputerList.Rows.Clear()
If count > 0 Then
For i As Integer = 0 To count - 1 Step 1
row1 = resultCollection(i).GetDirectoryEntry.Properties("CN").Value
row2 = resultCollection(i).Properties("canonicalName")(0)
dgvComputerList.Rows.Add(row1, row2)
ProgressBar1.Value = i
Next i
End If
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
dirEntry.Close()
End Sub
Public Sub ResetPass()
'This sub resets the Ad Pass of the selected user and even includes a neat password generator
Try
Dim newpass As String = "12345678"
If resetchk.txtNewPass.Text = "" Then
MessageBox.Show("Please enter a password.")
Exit Sub
Else
newpass = resetchk.txtNewPass.Text
End If
If tbxUserName.Text = "" Then
MessageBox.Show("Please enter a user first.")
Exit Sub
End If
Dim auser As String = tbxUserName.Text
Dim notFound As Boolean = True
Dim userLDAPpath As String
For Each userLDAPpath In userLDAPPaths
Dim dirEntry As New DirectoryEntry("LDAP://" & userLDAPpath)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(objectClass=user)(SAMAccountName=" & auser & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
notFound = False
Dim dirEntryResults As New DirectoryEntry(results.Path)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
dirEntryResults.Invoke("SetPassword", newpass)
If newpass = "12345678" Then
dirEntryResults.Properties("pwdLastSet").Value = "0"
End If
dirEntryResults.CommitChanges()
dirEntryResults.Close()
If newpass = "12345678" Then
MessageBox.Show("The password for " & auser & vbCrLf & "has been reset to " & newpass & vbCrLf & auser & " will be required to change it at next logon.")
Else
MessageBox.Show("The password for " & auser & vbCrLf & "has been reset to " & newpass)
End If
End If
dirEntry.Close()
Next
If notFound Then
MessageBox.Show("Error - unable to locate specified user.")
End If
Catch ex As Exception
MessageBox.Show("Error - you do not have permission to reset this user's password.")
End Try
End Sub
Function GetCurrentUserGroups()
'This sub enumerates the active directory group membership of the person using the program
Try
Dim MySelf As String = System.Environment.UserName.ToString
Dim ADPath As String = "LDAP://" + LDAPBaseDN
Dim dirEntry As New DirectoryEntry(ADPath)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(objectClass=user)(SAMAccountName=" & MySelf & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
Dim DirectoryEntryTheGroup As New DirectoryEntry(results.Path)
DirectoryEntryTheGroup.Username = Nothing
DirectoryEntryTheGroup.Password = Nothing
DirectoryEntryTheGroup.AuthenticationType = AuthenticationTypes.Secure
For Each group As String In DirectoryEntryTheGroup.Properties("memberOf").Value
If group.ToLower.IndexOf("domain admins") <> -1 Or _
group.ToLower.IndexOf("canresetitpass") <> -1 Then
Return True
DirectoryEntryTheGroup.Close()
Exit Function
End If
Next
DirectoryEntryTheGroup.Close()
Return False
Else
Return False
End If
dirEntry.Close()
Catch ex As Exception
Return False
End Try
End Function
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnXit.Click
Me.Close()
End Sub
Sub ClearAllFeilds()
'Quick sub to clear all the txt and forms on the main form
tbxTitle.Text = ""
tbxDept.Text = ""
tbxOffice.Text = ""
tbxCompany.Text = ""
tbxAddress.Text = ""
tbxCity.Text = ""
cboState.Text = ""
tbxZip.Text = ""
tbxTel.Text = ""
tbxFax.Text = ""
TextBoxDiscription.Text = ""
tbxProfilePath.Text = ""
TextBoxCellPhone.Text = ""
TextBoxADPName.Text = ""
LabelADPID.Text = ""
ClearExtraAccountInfo()
End Sub
Private Sub tbxUserName_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Run these when opened
GetTheINIs()
PsexecExist()
ChkForNewVersions()
CheckMeGroups()
ClearExtraAccountInfo()
psexecKey()
MakeDisableWallpaperBatch()
If ((File.Exists("C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1") = True) And _
(MegroupsCheck("domain admins") = True)) Then
MailboxSize.Visible = True
End If
Me.Refresh()
End Sub
Sub CheckMeGroups()
'Check what groups I belong to
Try
Dim MySelf As String = System.Environment.UserName.ToString
Dim ADPath As String = "LDAP://" + LDAPBaseDN
Dim dirEntry As New DirectoryEntry(ADPath)
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(objectClass=user)(SAMAccountName=" & MySelf & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim results As SearchResult = dirSearcher.FindOne()
If Not results Is Nothing Then
Dim DirectoryEntryTheGroup As New DirectoryEntry(results.Path)
DirectoryEntryTheGroup.Username = Nothing
DirectoryEntryTheGroup.Password = Nothing
DirectoryEntryTheGroup.AuthenticationType = AuthenticationTypes.Secure
Dim MeGroupsIndexCount As Integer = 1
For Each group As String In DirectoryEntryTheGroup.Properties("memberOf").Value
If MeGroups Is Nothing Then
ReDim MeGroups(1)
MeGroups(0) = group.ToLower.ToString
Continue For
End If
ReDim Preserve MeGroups(MeGroupsIndexCount + 1)
MeGroups(MeGroupsIndexCount) = group.ToLower.ToString
MeGroupsIndexCount += 1
If MeGroupsIndexCount > 6 Then
MeGroupsIndexCount = MeGroupsIndexCount
End If
Next
DirectoryEntryTheGroup.Close()
Else
End If
dirEntry.Close()
Catch ex As Exception
End Try
End Sub
Sub ChkForNewVersions()
'Checks a central share to see if I've created a new version. I plan to create an auto updater in the future.
'THIS NEEDS TO BE UPDATED TO SUPPORT NON-CCM DOMAINS...
'Or i guess we could give Jim and Ed permission to this share or create a specific one. We'll see.
Dim ThisProgram As String = ""
Dim ThatProgram As String = ""
Try
ThisProgram = System.Diagnostics.FileVersionInfo.GetVersionInfo("SyntecADUserEditor.exe").ProductVersion
ThatProgram = System.Diagnostics.FileVersionInfo.GetVersionInfo("\\ccmfs\software$\CCMUserEditor\SyntecADUserEditor.exe").ProductVersion