<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=2851&amp;type=atom" />
	<updated>2011-04-17T10:51:16Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=2851</id>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47674#p47674" />
			<content type="html"><![CDATA[<p><strong>TAOSoft</strong>, воспользуйтесь обратной функцией преобразования, наподобие:<br /></p><div class="codebox"><pre><code>Option Explicit

Const HKEY_CURRENT_USER = &amp;H80000001

Dim objSWbemServicesEx
Dim objSWbemObjectEx

Dim arrValues


Set objSWbemServicesEx = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\default&quot;)
Set objSWbemObjectEx   = objSWbemServicesEx.Get(&quot;StdRegProv&quot;)

If objSWbemObjectEx.GetBinaryValue(HKEY_CURRENT_USER, _
    &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot;, &quot;UserName&quot;, arrValues) = 0 Then
    
    WScript.Echo HexArray2Str(arrValues)
Else
    WScript.Echo &quot;Error reading registry&quot;
End If

Set objSWbemObjectEx   = Nothing
Set objSWbemServicesEx = Nothing

WScript.Quit 0
&#039;=============================================================================

&#039;=============================================================================
Function HexArray2Str(arrValues)
    Dim strValue
    Dim i
    Dim intDValue
    Dim intBigValue, intLittleValue
    
    
    strValue = &quot;&quot;
    
    For i = LBound(arrValues) To UBound(arrValues) Step 2
        intLittleValue = arrValues(i)
        intBigValue    = arrValues(i + 1)
        intDValue      = intBigValue * &amp;H100 + intLittleValue
        
        strValue       = strValue &amp; ChrW(intDValue)
    Next
    
    HexArray2Str = Left(strValue, Len(strValue) - 1)
End Function
&#039;=============================================================================</code></pre></div><div class="quotebox"><cite>TAOSoft пишет:</cite><blockquote><p>&#039;проверка т.к обычно 0 используется как разделитель между символами</p></blockquote></div><p>0 не используется в качестве разделителя между символами, Вы путаете. У латинских символов в юникоде старшее слово равно нулю.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-04-17T10:51:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47674#p47674</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47663#p47663" />
			<content type="html"><![CDATA[<p>Доброго времени суток уважаемые!</p><p>Подскажите пожалуйста, как получить значение параметра реестра (тип REG_BINARY). Т.е. после выполнения скрипта из 17 поста (при strUserName = &quot;Иванов&quot;) в реестре параметр UserName принимает значение 18,04,32,04,30,04,3d,04,3e,04,32,04,00,00, если прочитать это значение через GetBinaryValue, получаю &quot;кракозябры&quot;, а я хочу видеть Иванов. Подскажите, в какую сторону копать. Может быть, у кого есть готовое решение. Заранее благодарен<br /></p><div class="codebox"><pre><code>const HKEY_CURRENT_USER = &amp;H80000001
 
&#039;подключение к реестру 
Set objReg = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv&quot;) 
If Err.Number &lt;&gt; 0 Then 
  WScript.Echo Err.Number &amp; &quot;: &quot; &amp; Err.Description 
  WScript.Quit 
End If 
&#039; путь к разделу  
path = &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot; 
&#039; параметр который нужно прочетать 
Param = &quot;UserName&quot;  
&#039; чтение параметра 
intRes = ObjReg.GetBinaryValue(HKEY_CURRENT_USER, Path, Param, Value) 
If intRes &lt;&gt; 0 Then 
  strErr = StrErr &amp; intRes &amp; &quot;: не удалась прочитать значение параметра &quot;&quot;HKEY_CURRENT_USER\&quot;  &amp; Path &amp; &quot;\&quot; &amp; Param &amp; &quot;&quot;&quot;&quot; 
Else 
  For i = lBound(value) To UBound(Value) 
    &#039;проверка т.к обычно 0 используется как разделитель между символами 
    If value(i) &lt;&gt; 0 Then 
      Temp = Temp &amp; Chr(Value(i))
    End If 
  Next 
Wscript.Echo Temp
End If</code></pre></div>]]></content>
			<author>
				<name><![CDATA[TAOSoft]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26905</uri>
			</author>
			<updated>2011-04-16T20:00:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47663#p47663</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44683#p44683" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Кажись, теперь начинаю припоминать <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" />, зачем в <a href="http://forum.script-coding.com/viewtopic.php?pid=20034#p20034">#2</a> было:<br /></p><div class="codebox"><pre><code>strValue = strValue &amp; Chr(0)</code></pre></div></blockquote></div><p>Спасибо, заработало <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><p>Тоже пытался это куда-нибудь засунуть, но не работало <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><br /><p>Вот конечный вариант:<br /></p><div class="codebox"><pre><code>On Error Resume Next

&#039;-------------------------------------
&#039;Функция перевода строки в бинарный массив
&#039;-------------------------------------

Function Str2HexArray(strValue) 
        strValue = strValue &amp; Chr(0)
        
    ReDim arrValues(LenB(strValue) - 1)
    
    Dim d
    Dim intDValue
    Dim intBigValue, intLittleValue

    For d = 1 To Len(strValue)
        intDValue      = AscW(Mid(strValue, d, 1))
        intBigValue    = intDValue \ &amp;HFF
        intLittleValue = (intDValue - intBigValue) Mod &amp;HFF
        
        arrValues(d * 2 - 2) = intLittleValue
        arrValues(d * 2 - 1) = intBigValue
    Next
    
        Str2HexArray = arrValues
End Function

&#039;-------------------------------------
&#039;Функция записи в реестр
&#039;-------------------------------------
function SetRegistration( sUserName, sUserInitials, sCompany) 
const HKCU = &amp;H80000001

dim oReg
set oReg = getobject(&quot;winMgmts:\\.\root\default:StdRegProv&quot;)
dim sKey

&#039;-------- Для MS Office 2000 -----------------------------------
sKey = &quot;Software\Microsoft\Office\9.0\Common\UserInfo&quot;

oReg.SetBinaryValue HKCU, sKey, &quot;UserName&quot; , Str2HexArray( sUserName)
oReg.SetBinaryValue HKCU, sKey, &quot;UserInitials&quot; , Str2HexArray( sUserInitials)
oReg.SetBinaryValue HKCU, sKey, &quot;Company&quot; , Str2HexArray( sCompany)

oReg.SetDWORDValue HKCU, &quot;Software\Microsoft\Office\9.0\MS Project\Options\General&quot;, &quot;Is User Name Set&quot;, 0

&#039;-------- Для MS Office 2003 -----------------------------------
sKey = &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot;

oReg.SetBinaryValue HKCU, sKey, &quot;UserName&quot; , Str2HexArray( sUserName)
oReg.SetBinaryValue HKCU, sKey, &quot;UserInitials&quot; , Str2HexArray( sUserInitials)
oReg.SetBinaryValue HKCU, sKey, &quot;Company&quot; , Str2HexArray( sCompany)

oReg.SetDWORDValue HKCU, &quot;Software\Microsoft\Office\11.0\MS Project\Options\General&quot;, &quot;Is User Name Set&quot;, 0

&#039;-------- Для MS Office 2007, 2010 -----------------------------
sKey = &quot;Software\Microsoft\Office\Common\UserInfo&quot;

oReg.SetStringValue HKCU, sKey, &quot;UserName&quot; , sUserName
oReg.SetStringValue HKCU, sKey, &quot;UserInitials&quot; , sUserInitials
oReg.SetStringValue HKCU, sKey, &quot;Company&quot; , sCompany
oReg.SetStringValue HKCU, sKey, &quot;CompanyName&quot; , sCompany

oReg.SetBinaryValue HKCU, &quot;Software\Microsoft\Office\12.0\Common\UserInfo&quot;, &quot;Company&quot;, Str2HexArray( sCompany)
oReg.SetDWORDValue HKCU, &quot;Software\Microsoft\Office\12.0\MS Project\Options\General&quot;, &quot;Is User Name Set&quot;, 0
end function 

&#039;инициализация переменных
&#039;-------------------------------------
&#039;имя компьютера
strComputer = &quot;.&quot;

&#039;Имя организации
strCompany = &quot;Название организации&quot;

&#039;Инициалы пользователя
strUserInitials = &quot;&quot;

&#039;имя пользователя
strUserName = &quot;&quot;

&#039;-------------------------------------
&#039;получение данных пользователя
&#039;-------------------------------------
Set objADSystemInfo = CreateObject(&quot;ADSystemInfo&quot;)
Set objUser = GetObject(&quot;LDAP://&quot; &amp; objADSystemInfo.UserName)

strUserName = objUser.displayName
strUserInitials = objUser.displayName 

&#039;------- Выделение инициалов --------------
strArray = Split(strUserInitials, &quot; &quot;, 3) 
For i = 0 To Ubound(strArray) 
    If i = 0 Then 
        strUserInitials = Left(strArray(i), 1) &amp; &quot;.&quot; 
    Else 
        strUserInitials = strUserInitials &amp; Left(strArray(i), 1) &amp; &quot;.&quot; 
    End If 
Next 

&#039;----------- Регистрация переменных -----------------
SetRegistration strUserName, strUserInitials, strCompany</code></pre></div>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-02-01T07:38:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44683#p44683</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44682#p44682" />
			<content type="html"><![CDATA[<p>Кажись, теперь начинаю припоминать <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" />, зачем в <a href="http://forum.script-coding.com/viewtopic.php?pid=20034#p20034">#2</a> было:<br /></p><div class="codebox"><pre><code>strUsername = strUsername &amp; Chr(0)</code></pre></div><p>Попробуйте добавить в функцию из <a href="http://forum.script-coding.com/viewtopic.php?pid=44614#p44614">#8</a> сие первой строкой, наподобие:<br /></p><div class="codebox"><pre><code>Function Str2HexArray(strValue)
    strValue = strValue &amp; Chr(0)
    
    ReDim arrValues(LenB(strValue) - 1)
    
    Dim i
    Dim intDValue
    Dim intBigValue, intLittleValue
    
    For i = 1 To Len(strValue)
        intDValue      = AscW(Mid(strValue, i, 1))
        intBigValue    = intDValue \ &amp;HFF
        intLittleValue = (intDValue - intBigValue) Mod &amp;HFF
        
        arrValues(i * 2 - 2) = intLittleValue
        arrValues(i * 2 - 1) = intBigValue
    Next
    
    Str2HexArray = arrValues
End Function</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-02-01T07:29:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44682#p44682</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44681#p44681" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Выберете <a href="http://forum.script-coding.info/viewtopic.php?pid=14545#p14545">отсюда</a> подходящее Вам. И вообще посмотреть поиском по форуму по ключевому слову «ADSystemInfo».</p></blockquote></div><p>Спасибо, анализирую данные <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Меня интересовали исходные данные и пример, позволяющий воспроизвести то, что получается у Вас. Ну, ладно, коль Вы уже как-то решили — теперь не важно.</p></blockquote></div><p>Исходные данные ФИО пользователя из домена: Фамилия Имя Отчество.<br />Я так понял что получившийся массив либо не дописывает преобразования до конца, либо в Ms Office требуется ограничивать конец строки пустым символом.<br />Нет, я так и не решил данную проблему, при попытке выяснить причину обнаружил что строки должны заканчиваться с двумя пустыми знаками, т.е. иметь код 00 00.<br />По аналогии с исходным скриптом, который я выкладывал, добавить недостоющие знаки не получается, прошу помочь <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Т.е. надо обязательно дописывать на выход преобразования &quot;00,00&quot;</p>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-02-01T02:04:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44681#p44681</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44680#p44680" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Мне нужно получить только текущее имя пользователя, взятое из домена.</p></blockquote></div><p>Выберете <a href="http://forum.script-coding.info/viewtopic.php?pid=14545#p14545">отсюда</a> подходящее Вам. И вообще посмотреть поиском по форуму по ключевому слову «ADSystemInfo».<br /></p><div class="quotebox"><cite>a154802 пишет:</cite><blockquote><div class="quotebox"><cite>alexii пишет:</cite><blockquote><div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Появилась проблемка, при конвертации получается правильная последовательность, но либо не хватает окончания, либо обрузаются последние знаки кодировки.</p></blockquote></div><p>Приведите подробный пример.</p></blockquote></div><p>Исправляется если добавить в раздел реестра необходимые 00 00 , тогда ошибок нету.</p></blockquote></div><p>Меня интересовали исходные данные и пример, позволяющий воспроизвести то, что получается у Вас. Ну, ладно, коль Вы уже как-то решили — теперь не важно.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-01-31T19:36:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44680#p44680</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44676#p44676" />
			<content type="html"><![CDATA[<p>Не, тогда проверка точно не нужна, т.к. всегда используются только буквы или цифры.<br />Исправляется если добавить к полученным значениям необходимые 00 00 в конце, тогда ошибок нету.</p><p><span class="postimg"><img src="http://teranyu.homeip.net/temp/vbs/error.PNG" alt="http://teranyu.homeip.net/temp/vbs/error.PNG" /></span></p><p>OFF</p><p>Мне нужно получить только текущее имя пользователя, взятое из домена.</p>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-01-31T17:00:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44676#p44676</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44645#p44645" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>А можно как-то добавить проверку (хотя не знаю, нужна она или нет).</p></blockquote></div><p>Ну, если вдруг надумаете передавать в функцию пустую строку или вовсе не строку — то можно.<br /></p><div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Появилась проблемка, при конвертации получается правильная последовательность, но либо не хватает окончания, либо обрузаются последние знаки кодировки.</p></blockquote></div><p>Приведите подробный пример.</p><p>OFF:<br /></p><div class="quotebox"><cite>Win32_NetworkLoginProfile class пишет:</cite><blockquote><p><strong>Remarks</strong><br />…<br />The calling process that uses this class must have the SE_RESTORE_NAME privilege on the computer in which the registry resides.<br />…</p></blockquote></div><div class="codebox"><pre><code>…{impersonationLevel=impersonate,(Restore)}…</code></pre></div><p>Или сие специально было убрано, чтобы только текущего получить?</p><p>P.S. Какой-то очень странный метод получения имени Вы выбрали.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-01-31T08:56:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44645#p44645</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44639#p44639" />
			<content type="html"><![CDATA[<p>Прошу прощения за цитирование.</p><p>А можно как-то добавить проверку (хотя не знаю, нужна она или нет).<br />Появилась проблемка, при конвертации получается правильная последовательность, но либо не хватает окончания, либо обрузаются последние знаки кодировки.</p><div class="codebox"><pre><code>On Error Resume Next

&#039;-------------------------------------
&#039;Функция перевода строки в бинарный массив
&#039;-------------------------------------

Function Str2HexArray(strValue) 

    ReDim arrValues(LenB(strValue) - 1)
    
    Dim d
    Dim intDValue
    Dim intBigValue, intLittleValue

    For d = 1 To Len(strValue)
        intDValue      = AscW(Mid(strValue, d, 1))
        intBigValue    = intDValue \ &amp;HFF
        intLittleValue = (intDValue - intBigValue) Mod &amp;HFF
        
        arrValues(d * 2 - 2) = intLittleValue
        arrValues(d * 2 - 1) = intBigValue
    Next
        Str2HexArray = arrValues
End Function


&#039;-------------------------------------
&#039;Функция записи в реестр
&#039;-------------------------------------
function SetRegistration( sUserName, sUserInitials, sCompany) 
const HKCU = &amp;H80000001

dim oReg
set oReg = getobject(&quot;winMgmts:\\.\root\default:StdRegProv&quot;)
dim sKey

&#039;--------for MS Office 2003-----------------------------------
sKey = &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot;

oReg.SetBinaryValue HKCU, sKey, &quot;UserName&quot; , Str2HexArray( sUserName)
oReg.SetBinaryValue HKCU, sKey, &quot;UserInitials&quot; , Str2HexArray( sUserInitials)
oReg.SetBinaryValue HKCU, sKey, &quot;Company&quot; , Str2HexArray( sCompany)

oReg.SetDWORDValue HKCU, &quot;Software\Microsoft\Office\11.0\MS Project\Options\General&quot;, &quot;Is User Name Set&quot;, 0

&#039;--------for MS Office 2007-----------------------------------
sKey = &quot;Software\Microsoft\Office\Common\UserInfo&quot;

oReg.SetStringValue HKCU, sKey, &quot;UserName&quot; , sUserName
oReg.SetStringValue HKCU, sKey, &quot;UserInitials&quot; , sUserInitials
oReg.SetStringValue HKCU, sKey, &quot;Company&quot; , sCompany
oReg.SetStringValue HKCU, sKey, &quot;CompanyName&quot; , sCompany

oReg.SetBinaryValue HKCU, &quot;Software\Microsoft\Office\12.0\Common\UserInfo&quot;, &quot;Company&quot;, Str2HexArray( sCompany)
oReg.SetDWORDValue HKCU, &quot;Software\Microsoft\Office\12.0\MS Project\Options\General&quot;, &quot;Is User Name Set&quot;, 0
end function 

&#039;инициализация переменных
&#039;-------------------------------------
&#039;имя компьютера
strComputer = &quot;.&quot;

&#039;Имя организации
strCompany = &quot;Название организации&quot;

&#039;Инициалы пользователя
strUserInitials = &quot;&quot;

&#039;имя пользователя
strUserName = &quot;&quot;


&#039;-------------------------------------
&#039;получение данных пользователя
&#039;-------------------------------------
&#039;set WSHShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
Set objWMIService = GetObject(&quot;winmgmts:&quot; &amp; &quot;{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)  
Set colComputer = objWMIService.ExecQuery(&quot;Select * from Win32_NetworkLoginProfile where FullName is not null&quot;,,48)
Set oReg=GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\default:StdRegProv&quot;) 

For Each objComputer in colComputer
strUserName = objComputer.FullName
strUserInitials = objComputer.FullName 

Next 
strArray = Split(strUserInitials, &quot; &quot;, 3) 
For i = 0 To Ubound(strArray) 
    If i = 0 Then 
        strUserInitials = Left(strArray(i), 1) &amp; &quot;.&quot; 
    Else 
        strUserInitials = strUserInitials &amp; Left(strArray(i), 1) &amp; &quot;.&quot; 
    End If 
Next 


SetRegistration strUserName, strUserInitials, strCompany</code></pre></div>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-01-31T06:16:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44639#p44639</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44622#p44622" />
			<content type="html"><![CDATA[<p><span style="color: Green"><strong>a154802</strong>, избегайте излишнего цитирования. Я поправил Ваш предыдущий пост.</span></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-01-30T18:12:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44622#p44622</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44615#p44615" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Добавить универсальность, что бы данная функция выполняла много разных обработок, а не для каждого значения свой обработчик городить.</p></blockquote></div><p>Вы про это, что ли?!<br />…</p></blockquote></div><p>Спасибо!<br />То, что нужно <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-01-30T16:49:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44615#p44615</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44614#p44614" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>a154802 пишет:</cite><blockquote><p>Добавить универсальность, что бы данная функция выполняла много разных обработок, а не для каждого значения свой обработчик городить.</p></blockquote></div><p>Вы про это, что ли?!<br /></p><div class="codebox"><pre><code>Function Str2HexArray(strValue)
    ReDim arrValues(LenB(strValue) - 1)
    
    Dim i
    Dim intDValue
    Dim intBigValue, intLittleValue
    
    For i = 1 To Len(strValue)
        intDValue      = AscW(Mid(strValue, i, 1))
        intBigValue    = intDValue \ &amp;HFF
        intLittleValue = (intDValue - intBigValue) Mod &amp;HFF
        
        arrValues(i * 2 - 2) = intLittleValue
        arrValues(i * 2 - 1) = intBigValue
    Next
    
    Str2HexArray = arrValues
End Function</code></pre></div><p>P.S. Без каких-либо проверок.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-01-30T16:31:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44614#p44614</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44613#p44613" />
			<content type="html"><![CDATA[<p>Конечная цель:<br />Сделать его как обработчик, что бы можно было указать, к примеру, arrBinary( sCompany) и выполнилось преобразование данных sCompany и получить обработанные данные.<br />Добавить универсальность, что бы данная функция выполняла много разных обработок, а не для каждого значения свой обработчик городить.</p><p>P.S.<br />На основе Ваших замечаний и исходниками <strong>abasov</strong>, модифицировал для себя, но преобразование в бинарный вид происходит 2 раза, для strUsername и strCompany, а так можно было бы обойтись одним, заменяя нужные переменные &quot;на лету&quot;.</p><div class="codebox"><pre><code>Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;) 
set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;) 
&#039; get UserName 
strName = WshShell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;) 

On Error Resume Next 

&#039; Constants for the NameTranslate object. 
Const ADS_NAME_INITTYPE_DOMAIN = 1 
Const ADS_NAME_TYPE_NT4 = 3 
Const ADS_NAME_TYPE_1179 = 1 

Set objNetwork = CreateObject(&quot;Wscript.Network&quot;) 

&#039; Determine DNS domain name from RootDSE object. 
Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;) 
If Err.Number &lt;&gt; 0 Then 
Wscript.Quit 
End If 
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;) 

&#039; Use the NameTranslate object to find the NetBIOS domain name from the 
&#039; DNS domain name. 
Set objTrans = CreateObject(&quot;NameTranslate&quot;) 
objTrans.Init ADS_NAME_TYPE_NT4, strDNSDomain 
objTrans.Set ADS_NAME_TYPE_1179, strDNSDomain 
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) 
&#039; Remove trailing backslash. 
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) 

&#039; Use the NameTranslate object to convert the NT user name to the 
&#039; Distinguished Name required for the LDAP provider. 
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain 
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain &amp; &quot;\&quot; &amp; strName 
strUserDN = objTrans.Get(ADS_NAME_TYPE_1179) 

&#039; Bind to the user object in Active Directory with the LDAP provider. 
Set objUser = GetObject(&quot;LDAP://&quot; &amp; strUserDN) 

&#039;Get Common name 
strUsername=objUser.Get(&quot;displayName&quot;) &#039; &amp; &quot;, &quot; &amp; objUser.Get(&quot;telephoneNumber&quot;) 
&#039;strUsername= objUser.cn 

&#039;Имя организации
strCompany = &quot;Название организации&quot;

&#039;WScript.Echo strUsername 
&#039;Convert Initials to HEX 
Const HKEY_CURRENT_USER = &amp;H80000001 
Set objRegistry = GetObject(&quot;winmgmts:\\.\root\default:StdRegProv&quot;) 

&#039;----------------
strUsername = strUsername &amp; Chr(0) 
ReDim arrValues(LenB(strUsername) - 1) 

For i = 1 To Len(strUsername) 
intDValue = AscW(Mid(strUsername, i, 1)) 
intBigValue = intDValue \ &amp;HFF 
intLittleValue = (intDValue - intBigValue) Mod &amp;HFF 

arrValues(i * 2 - 2) = intLittleValue 
arrValues(i * 2 - 1) = intBigValue 
Next 

&#039;----------------
strCompany = strCompany &amp; Chr(0) 
ReDim arrCompany(LenB(strCompany) - 1) 

For i = 1 To Len(strCompany) 
intDValue = AscW(Mid(strCompany, i, 1)) 
intBigValue = intDValue \ &amp;HFF 
intLittleValue = (intDValue - intBigValue) Mod &amp;HFF 

arrCompany(i * 2 - 2) = intLittleValue 
arrCompany(i * 2 - 1) = intBigValue 
Next 

&#039;------------------

&#039;--------for MS Office 2003-----------------------------------
errReturn = objRegistry.SetBinaryValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot;, &quot;UserName&quot;, arrValues) 
errReturn = objRegistry.SetBinaryValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\11.0\Common\UserInfo&quot;, &quot;Company&quot;, arrCompany) 


&#039;--------for MS Office 2007-----------------------------------
errReturn = objRegistry.SetStringValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\Common\UserInfo&quot;, &quot;UserName&quot;, strUsername) 
errReturn = objRegistry.SetStringValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\Common\UserInfo&quot;, &quot;Company&quot;, strCompany)
errReturn = objRegistry.SetStringValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\Common\UserInfo&quot;, &quot;CompanyName&quot;, strCompany) 
&#039;errReturn = objRegistry.SetStringValue (HKEY_CURRENT_USER, &quot;Software\Microsoft\Office\Common\UserInfo&quot;, &quot;UserInitials&quot;, strInitial) 



Set objRegistry = Nothing</code></pre></div><p>P.P.S.</p><p>Не совсем разобрался как сделать инициалы с разделением в виде точек.</p>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-01-30T15:05:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44613#p44613</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44609#p44609" />
			<content type="html"><![CDATA[<p><strong>a154802</strong>, Ваш вопрос не понятен. Укажите конечную цель.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-01-30T14:40:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44609#p44609</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: Формирование ФИО в авторе Office 2003 из AD]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=44597#p44597" />
			<content type="html"><![CDATA[<p>Прошу помочь.</p><p>Как из вышеукащанного преобразования сделать массив функции?</p><p>Если правильно понял, то конвертация происходит только здесь:<br /></p><div class="codebox"><pre><code>strUsername = strUsername &amp; Chr(0)
ReDim arrValues(LenB(strUsername) - 1)

For i = 1 To Len(strUsername)
    intDValue      = AscW(Mid(strUsername, i, 1))
    intBigValue    = intDValue \ &amp;HFF
    intLittleValue = (intDValue - intBigValue) Mod &amp;HFF
    
    arrValues(i * 2 - 2) = intLittleValue
    arrValues(i * 2 - 1) = intBigValue
Next</code></pre></div><p>Пытаюсь преобразовать в вид:<br /></p><div class="codebox"><pre><code>function arrBinary( sString)
dim s, i
s = &quot;&quot;
for i = 1 to len( sString)
s = s &amp; &quot;,&quot; &amp; asc(mid( sString, i, 1)) &amp; &quot;,&quot; &amp; &quot;00&quot;
next
arrBinary = split( mid( s &amp; &quot;,00,00&quot;, 2), &quot;,&quot;)
end function</code></pre></div><p>Пытаюсь видоизменить этот скрипт: <a href="http://forum.tsure.ru/index.php?showtopic=50459">http://forum.tsure.ru/index.php?showtopic=50459</a></p>]]></content>
			<author>
				<name><![CDATA[a154802]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26538</uri>
			</author>
			<updated>2011-01-30T10:10:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=44597#p44597</id>
		</entry>
</feed>
